| View previous topic :: View next topic |
| Author |
Message |
Anton Feiertag Guest
|
Posted: Mon Jan 12, 2004 2:27 pm Post subject: Variable removed due to Optimization!!! |
|
|
Hi All
I sometimes gets the message "variable removed due to optimization", and
then I can't inspect it. Is there a way arround this. That is, to have all
variables available at all times. I don't have optimization switched on.
Kind greetings
Anton Feiertag
|
|
| Back to top |
|
 |
Jose Perez Guest
|
Posted: Mon Jan 12, 2004 3:15 pm Post subject: Re: Variable removed due to Optimization!!! |
|
|
"Anton Feiertag" <anton (AT) dokker (DOT) com> wrote
| Quote: | Hi All
I sometimes gets the message "variable removed due to optimization", and
then I can't inspect it. Is there a way arround this. That is, to have all
variables available at all times. I don't have optimization switched on.
|
This message should only appear if the variable is not referenced in your
code. That is, it was declared, but not used.
| Quote: | Kind greetings
Anton Feiertag
|
|
|
| Back to top |
|
 |
Andreas Schmidt Guest
|
Posted: Mon Jan 12, 2004 3:27 pm Post subject: Re: Variable removed due to Optimization!!! |
|
|
"Anton Feiertag" <anton (AT) dokker (DOT) com> schrieb im Newsbeitrag
news:btuat5$7mq$1 (AT) ctb-nnrp2 (DOT) saix.net...
| Quote: | I sometimes gets the message "variable removed due to optimization", and
then I can't inspect it. Is there a way arround this. That is, to have all
variables available at all times. I don't have optimization switched on.
|
Did you rebuild the whole project?
You should do so after changing a project option.
Andreas
|
|
| Back to top |
|
 |
Jamie Guest
|
Posted: Mon Jan 12, 2004 10:07 pm Post subject: Re: Variable removed due to Optimization!!! |
|
|
if you make to usable reference to the variable in your code the
compiler will remove it.
if your using it to test some results you simply make a reference to
it in your code so that the compiler won't remove it.
Anton Feiertag wrote:
| Quote: | Hi All
I sometimes gets the message "variable removed due to optimization", and
then I can't inspect it. Is there a way arround this. That is, to have all
variables available at all times. I don't have optimization switched on.
Kind greetings
Anton Feiertag
|
|
|
| Back to top |
|
 |
Anton Feiertag Guest
|
Posted: Thu Jan 15, 2004 9:34 am Post subject: Re: Variable removed due to Optimization!!! |
|
|
I can assure you that the variable is referenced. I have declared it and
used it in statements in that function/procedure but when I put the mouse on
it or with CTRL-F7 it says that it was removed due to optimization. I am
then forced to use a ShowMessage(Variable) to see its contents.
Greetings
Anton
"Jose Perez" <jomperez (AT) optonline (DOT) net> wrote
| Quote: | "Anton Feiertag" <anton (AT) dokker (DOT) com> wrote in message
news:btuat5$7mq$1 (AT) ctb-nnrp2 (DOT) saix.net...
Hi All
I sometimes gets the message "variable removed due to optimization", and
then I can't inspect it. Is there a way arround this. That is, to have
all
variables available at all times. I don't have optimization switched on.
This message should only appear if the variable is not referenced in your
code. That is, it was declared, but not used.
Kind greetings
Anton Feiertag
|
|
|
| Back to top |
|
 |
J French Guest
|
Posted: Thu Jan 15, 2004 10:13 am Post subject: Re: Variable removed due to Optimization!!! |
|
|
On Thu, 15 Jan 2004 11:34:32 +0200, "Anton Feiertag"
<anton (AT) dokker (DOT) com> wrote:
| Quote: | I can assure you that the variable is referenced. I have declared it and
used it in statements in that function/procedure but when I put the mouse on
it or with CTRL-F7 it says that it was removed due to optimization. I am
then forced to use a ShowMessage(Variable) to see its contents.
|
Yes - that can happen
- this is because the compiler has decided that it does not need the
variable
- typically (I guess) when it has decided to keep the value in a
register
I think that your best bet is to send the variable to a routine where,
if a flag is set, you do a ShowMessage
- that normally foxes the compiler
|
|
| Back to top |
|
 |
Nicolai Hansen Guest
|
Posted: Thu Jan 15, 2004 2:21 pm Post subject: Re: Variable removed due to Optimization!!! |
|
|
"Anton Feiertag" <anton (AT) dokker (DOT) com> wrote
| Quote: | Hi All
I sometimes gets the message "variable removed due to optimization", and
then I can't inspect it. Is there a way arround this. That is, to have all
variables available at all times. I don't have optimization switched on.
Kind greetings
Anton Feiertag
|
There is a workaround for this. Declare a global pointer:
var
glP: Pointer;
Then, lets say you want to watch the variable "i", do the following
procedure TSomeType.SomeMethod;
var
i, j: integer;
begin
glP:=@i;
i:=10;
j:=i+5;
j:=j*2;
end;
-normally- "i" would be eliminated after the j:=i+5 line. But because
of the pointer, you can keep watching "i".
|
|
| Back to top |
|
 |
Bruce Roberts Guest
|
Posted: Thu Jan 15, 2004 3:26 pm Post subject: Re: Variable removed due to Optimization!!! |
|
|
"Anton Feiertag" <anton (AT) dokker (DOT) com> wrote
| Quote: | I can assure you that the variable is referenced. I have declared it and
used it in statements in that function/procedure but when I put the mouse
on
it or with CTRL-F7 it says that it was removed due to optimization. I am
then forced to use a ShowMessage(Variable) to see its contents.
|
A last reference to a local variable of the form
X := someExpression;
will likely mean that the compiler removes the statement, unless it involves
function or method calls. The assignment to X will, in any case, be
optimized out - its value is never used.
|
|
| Back to top |
|
 |
Terry Russell Guest
|
Posted: Fri Jan 16, 2004 1:12 am Post subject: Re: Variable removed due to Optimization!!! |
|
|
"Anton Feiertag" <anton (AT) dokker (DOT) com> wrote
| Quote: | I can assure you that the variable is referenced. I have declared it and
used it in statements in that function/procedure but when I put the mouse
on
it or with CTRL-F7 it says that it was removed due to optimization. I am
then forced to use a ShowMessage(Variable) to see its contents.
Greetings
Anton
|
if you select view->debug windows->local variables
Then step through the code you should see that with
optimisation ON the variable value is only accessible
when stepping within the range of code that references it..
Turning optimisation off doesn't necessarily mean the exe will be linked
with code compiled off.
The code may not be rebuilt, you may have otherwise fixed the units options.
eg ctrl+O+O inserts options at head of unit , overriding project options
|
|
| Back to top |
|
 |
|