A
A
Anton Savchenko2015-05-24 14:38:05
Delphi
Anton Savchenko, 2015-05-24 14:38:05

Variable problem in Delphi. What to do?

Declared a variable of type boolean in a function. Delphi sees it, but when debugging, it skips all the operations associated with it, and also displays a message that this variable is not used in the program. Rewrote the .exe file, didn't help.

Answer the question

In order to leave comments, you need to log in

6 answer(s)
B
bobrovskyserg, 2015-05-24
@bobrovskyserg

> they say this variable is not used in the program
That's right, and the memory (or register) is not allocated for it.
Take a close look at your code, maybe you have a complex boolean expression that is evaluated at compile time - and that's it.

C
Cyril, 2015-05-24
@endemic

In VisualStudio, when trying to debug a project compiled under the release configuration, there were sometimes such problems. Make sure you are using the debug config

A
Alexander, 2015-05-24
@AlanDrakes

If Delphi reports that the variable is not being used, it probably is.
The compiler most often analyzes whether there are data accesses inside the variable and, based on the result of this analysis, decides whether the variable is needed in the code.
Example1:

var
a: boolean;
<...>
begin
a:= false;
<...>
a:= true;
<...>
end;

Here, the variable is not accessed and is (from the compiler's point of view) useless.
Now like this:
var
a: boolean;
<...>
begin
a:= false;
<...>
a:= true;
<...>
return a;
end;

And here the value of the variable will be returned and ALL operations with it will remain.
Actually, nothing else.
Either use the variable in code, or remove it.

A
Alexander Gusev, 2015-05-25
@Sanchogus

If you look for where to turn off "optimization", then try to put in a thread if (variable = true) then inc (k);
in order for there to be any action that depends on the variable, it will have to eventually include it.

V
Vladimir Martyanov, 2015-05-24
@vilgeforce

Is it used in the program at all?

M
Mercury13, 2015-05-25
@Mercury13

If you need it so much, turn off optimization in the compilation settings.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question