Sign in Join

Live chat for Free Pascal, Lazarus, Delphi and every Pascal programmer.

Mailing lists / fpc-devel / 2009-07

Assign Self

7 messages · 3 people ·

Reply by email Subscribe to this list Your subscription

Read-only archive. Use j and k to move between messages.

Micha Nelissen

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

Reply by email

Jonas Maebe
to Micha Nelissen: When would it be used? Micha
Micha Nelissen wrote 6 lines
Jonas Maebe wrote: > On 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?

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

Reply by email

Micha Nelissen
to Jonas Maebe
Jonas Maebe wrote
Note 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

Reply by email

Micha Nelissen
to Micha Nelissen
Micha Nelissen wrote 7 lines
procedure tcontractform.add; begin self:=tcontractform.create(owner); self.insert.enabled:=true; self.btnregion.enabled:=true; self.showmodal; end;

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

Reply by email