Zitat von Andrea Mauri <[email protected]>:

Dear Mattias,
thanks, now it works.
May I ask you what was the problem? I would like to contribute as much as possible in this project, more I understand more I can help.

I will try to explain:

property AfterConnect : TNotifyEvent read FAfterConnect write SetAfterConnect;

The write method is defined as:

procedure TCustomConnection.SetAfterConnect(const AValue: TNotifyEvent);
begin
  if FAfterConnect=AValue then exit;
  FAfterConnect:=AValue;
end;

The problem is that TNotifyEvent is a special "record" of two pointers: Data and Code. At runtime Data is the instance (the Self pointer) and Code is the address of the procedure. At designtime there is no address. Therefore the IDE creates a special fake event, with Data an unique ID and Code=nil.

The comparison "FAfterConnect=AValue" only compares code, not data. Probably it is for Delphi compatibility. Although I wonder, why this happen under mode objfpc. IMHO this feature is inconsistent and almost useless.

Because at designtime the code is always nil, FAfterConnect=AValue is always true. I worked around this by first assigning Code=1 and then Code=nil.

But there is still a bug in the TCustomConnection, because when you switch the event to the method of the same class, but another instance, TCustomConnection will ignore this.

I think, it would be better if FPC changes the comparison in mode objfpc.

Mattias



--
_______________________________________________
Lazarus mailing list
[email protected]
http://lists.lazarus.freepascal.org/mailman/listinfo/lazarus

Reply via email to