[lazarus] initialized objects?

Nicolas Aragon nico at clubdelphi.com
Mon May 17 14:44:06 EDT 1999


Hello,

On Sun, 16 May 1999 23:09:59 -0500, you wrote:

>TMyObj.this;
>begin
> edit := TEdit.Create(Self);
>edit.text := 'this works'     <-----this works just fine
>end;
>TMyObj.that;
>begin
>edit.Text := 'not cool';     <-----this is throwing a access violation ?
>end;
>I have checked everything I can possibly think of and cannot get stuff
>like this to work. I have been fighting access violations all day.
>If I check for assigned it evaluates true.  Like the pointers are
>getting hosed up..

Cliff, "Assigned" only tell you that the pointer isn't nil. It can't
tell you if the address is valid.

I'm *not sure*... but I think that, at least in Delphi, you can trust
that global variables are initialized to nil (all zeroes).

Object fields are also nil if the object constructor executes
TObject.Create first, which zero all fields. If not, you can't tell
which the initial value will be, unless you explicitely assign nil in
your constructor.

Local variables are never guarranteed to be nil cause they're taken
from the stack, that dynamically holds return addresses, parameters
and so on.

For object variables whose lifetime is longer than a function is a
good programming practice (but by no means forced) to assign nil just
after calling Free. Assigning nil in the constructor also helps to
avoid errors. I encourage you to take this precautions at least while
developing.

I'm overworked now and most likely I will, during next three or four
weeks. I hope to stay in touch, though

greetings

  Nico






More information about the Lazarus mailing list