Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations derfloh on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

@self returns not always the same value ?!

Status
Not open for further replies.

kittyyo

Programmer
Oct 17, 2001
89
AT
Hi there,

I came over a strange thing today, that is:

I have got an object A that manages several other objects and always passes them a reference to itself - using @self in the code.

In two different procedures of this object I evaluate @self:

[tt]
procedure A.Proc1 (...);
var
temp: Pointer;
begin
temp := @self;
...
end;

procedure A.Proc2 (...);
var
temp: Pointer;
begin
temp := @self;
...
end;
[/tt]

temp in Proc1 gets set to $12F738 (which is right), temp in Proc2 gets set to $12F6DC (throws a pointer exception later, as the value is wrong). Proc2 is executed after Proc1. I do not copy / clone / ... object A, so I do not have a clue why this happens.

I have already used a workaround for this (I use another variable that holds the first, right, value of @self) - but this is a stupid workaround... [evil]

Does anyone have an idea?

Thanks,
Anne
 
don't see the need playing with pointers here.

Code:
declaration
object A
...

object B
...
 public
  RefToA : A;
...


procedure A.proc1;

var ObjB : B;

begin
 ObjB:=B.Create;
 B.RefToA:=Self;
 ...
end;

this goes never wrong...

--------------------------------------
What You See Is What You Get
 
You're completely right... seems I do not know as much about Delphi as I should... [surprise][neutral]

Another question: is it the same with records as with objects, or would I need a pointer for a record if I wanted to refer to one?

Thanks a lot!
Anne
 
AFAIK, you'll need a pointer for a record. But why use a record when you can create your own class that will give you an object with the same structure as the record but the ease of working with an object?

-Dell
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top