Board index » delphi » Variable inaccessible due to optimization?

Variable inaccessible due to optimization?

I want to watch two integer variables, x and y, but Delphi 3 says that I can't because they are inaccessible due to optimization. How do I get around this?
Ren
 

Re:Variable inaccessible due to optimization?


Quote
On Mon, 07 Sep 1998 13:53:17 -0500, Renwick Preston <rpres...@phoenix.net> wrote:
> I want to watch two integer variables, x and y, but Delphi 3 says that I
> can't because they are inaccessible due to optimization. How do I get
> around this?

Simple, turn off optimization. You'll find the checkbox on the compiler tab
of the project options.

--
Take a look in Hagbard's World: |   w3ng - The WWW Norton Guide reader.
http://www.acemake.com/hagbard/ |     eg - Norton Guide reader for Linux.
http://www.hagbard.demon.co.uk/ |    weg - Norton Guide reader for Windows.
Free software, including........| dgscan - DGROUP scanner for Clipper.

Re:Variable inaccessible due to optimization?


Delphi Help: Variable '<name>' inaccessible here due to optimization

Description

The evaluator or watch statement is attempting to retrieve the value of
<name>, but the compiler was able to determine that the variables actual
lifetime ended prior to this inspection point.  This error will often occur
if the compiler determines a local variable is assigned a value that is not
used beyond a specific point in the program's control flow.

Example

The compiler realizes that the first assignment to 'a' is dead, since the
value is never used.  As such, it defers even using 'a' until the second
assignment occurs -- up until the point where 'c' is assigned to 'a', the
variable 'a' is considered to be dead and cannot be used by the evaluator.
Create a new application.
Place a button on the form.
Double click the button to be taken to the 'click' method.
Add a global variable, 'c', of type Integer to the implementation section.

The click method should read as:

  procedure TForm1.Button1Click(Sender: TObject);
    var a, b : integer;
  begin
    a := 10;
    b := 20;
    c := b;
    a := c;
  end;

Set a breakpoint on the assignment to 'c'.
Compile and run the application.
Press the button.
After the breakpoint is reached, open the evaluator (Run|Evaluate/Watch).
Evaluate 'a'.
The only solution is to only attempt to view variables which are known to
have live values.

----------End Help----------

- Erling G

Quote
Renwick Preston wrote in message <35F42B9D.77FD...@phoenix.net>...
>I want to watch two integer variables, x and y, but Delphi 3 says that I

can't because they are inaccessible due to optimization. How do I get around
this?
Quote
>Ren

Other Threads