Re:pointer vs. var parameter
Hi guys,
(sorry again for the english)
First of all, thank you very much for your help.
It seems that I'm not the only one having some trouble with this...but I
think I finally got the point.
To make a long story short, (with the help of Mike Orriss) everthing is
based on the way we're telling the compiler to handle the variable passed as
parameter.
Even if its a pointer, passing it by value doesn't allow us to modify its
"very nature" (its base address).
That is, we can deference the pointer to change the state or the properties
of the object but every changes made to the variable itself won't be pushed
back on the stack upon return.
Thats the job of the "pointer to a pointer" VAR qualifier.
Thanks again for your help.
Clment Boucher
P.S. As I work to improve my english, every comments will be appreciated.
Fell free to reply, specifiying where I made mistakes
Robert Marquardt <robert_marqua...@gmx.de> a crit dans le message :
38E9F353.2BF7...@gmx.de...
Quote
> TStringList is an object. An object is some memory.
> An object variable is a pointer which points to the object memory.
> you want to assign the object variable with some new object.
> Therefore you have to use var. var silently delivers the address
> (pointer to) of the variable. Usage of the var param name (assignment)
> silently dereferences this address/pointer.
> Clement Boucher schrieb:
> > Hi,
> > (sorry for the english)
> > As far I tought that I understood the way the pointers are handled in
> > Delphi.
> > I now face a problem with them. Help.
> > I use some kind of controler object to deconnect the creation of an
object.
> > Lets say:
> > unit Data
> > interface
> > var
> > MyList: TStringList;
> > ...
> > end;
> > unit Controler
> > interface
> > procedure CreateList(aList: TStringList);
> > implementation
> > procedure CreateList(aList: TStringList);
> > begin
> > aList := TStringList.Create;
> > end;
> > ...
> > end.
> > unit Main;
> > ...
> > Contoler.CreateList(Data.MyList);
> > ...
> > end.
> > This won't work (MyList will be kept to nil) if I don't declare the
aList
> > parameter as VAR aList.
> > What's the problem?
> > The aList object isn't pushed on the stack. A pointer is a pointer is a
> > pointer!
> > I can modify any VCL object passed in parameter without qualifying it as
a
> > pointer to a pointer (var).
> > It seems so a basic issue.... help...
> > Clement