BorlandTalk.com Forum Index BorlandTalk.com
Borland discussion newsgroups
 
Archives   FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

Variable removed due to Optimization!!!

 
Post new topic   Reply to topic    BorlandTalk.com Forum Index -> comp.lang.pascal.delphi.misc
View previous topic :: View next topic  
Author Message
Anton Feiertag
Guest





PostPosted: Mon Jan 12, 2004 2:27 pm    Post subject: Variable removed due to Optimization!!! Reply with 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
Jose Perez
Guest





PostPosted: Mon Jan 12, 2004 3:15 pm    Post subject: Re: Variable removed due to Optimization!!! Reply with quote



"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





PostPosted: Mon Jan 12, 2004 3:27 pm    Post subject: Re: Variable removed due to Optimization!!! Reply with quote




"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





PostPosted: Mon Jan 12, 2004 10:07 pm    Post subject: Re: Variable removed due to Optimization!!! Reply with quote

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





PostPosted: Thu Jan 15, 2004 9:34 am    Post subject: Re: Variable removed due to Optimization!!! Reply with 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


"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





PostPosted: Thu Jan 15, 2004 10:13 am    Post subject: Re: Variable removed due to Optimization!!! Reply with quote

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





PostPosted: Thu Jan 15, 2004 2:21 pm    Post subject: Re: Variable removed due to Optimization!!! Reply with quote

"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





PostPosted: Thu Jan 15, 2004 3:26 pm    Post subject: Re: Variable removed due to Optimization!!! Reply with quote


"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





PostPosted: Fri Jan 16, 2004 1:12 am    Post subject: Re: Variable removed due to Optimization!!! Reply with quote

"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
Display posts from previous:   
Post new topic   Reply to topic    BorlandTalk.com Forum Index -> comp.lang.pascal.delphi.misc All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2006 phpBB Group
SEO toolkit © 2004-2006 webmedic.