Hi,
Are we supposed to be able to assign to Self? FPC accepts the attached unit, but seems strange to me to allow this?
Micha

Mailing lists / fpc-devel / 2009-07
7 messages · 3 people ·
Reply by email Subscribe to this list Your subscription
Read-only archive. Use j and k to move between messages.
Hi,
Are we supposed to be able to assign to Self? FPC accepts the attached unit, but seems strange to me to allow this?
Micha
Micha Nelissen wroteAre we supposed to be able to assign to Self?
Yes.
FPC accepts the attached unit
Kylix also.
Jonas
Jonas Maebe wroteOn 11 Jul 2009, at 12:53, Micha Nelissen wrote: > Are we supposed to be able to assign to Self? Yes.
When would it be used?
Micha
In our previous episode, Micha Nelissen said:
> Yes. When would it be used?
Maybe something in pooled object creation?
When would it be used? Micha
You can find some examples here:
* http://www.google.com/codesearch?hl=en&q=%22self%3A%3D%22+lang%3Apascal
* http://www.google.com/codesearch?hl=en&q=%22self+%3A%3D%22+lang%3Apascal
Note that some hits, like the one in cgbase.pas of FPC, refer to the self parameter of objects, not of classes.
Jonas
Jonas Maebe wroteNote that some hits, like the one in cgbase.pas of FPC, refer to the self parameter of objects, not of classes.
... or a local variable or a field in a record ...
Only ones I found are TExpression and TContractForm, but those don't win a readability contest, like below one in which self is abused as a kind of temporary variable of the "right" type:
procedure tcontractform.add;
begin
self:=tcontractform.create(owner);
self.insert.enabled:=true;
self.btnregion.enabled:=true;
self.showmodal;
end;Gives me the creeps, but I guess nothing strange will happen as other people's references to the "original" Self aren't modified.
Micha
In this case I guess there is even a "memory leak" in the sense that Owner is usually "Application" which is a variable existing for lifetime of program. So although this temporary form is freed eventually it takes up memory until end of program lifetime AFAICS.
A temporary variable named "LeakedContractForm" would have been much clearer then :-P.
Or put Self.Free at the end which is even creepier.
Micha