Mattias Gaertner schrieb:
On Sat, 01 Oct 2011 08:39:42 +0100
Martin <[email protected]> wrote:

On 01/10/2011 07:53, Mattias Gaertner wrote:
On Sat, 01 Oct 2011 03:04:56 +0200
Hans-Peter Diettrich<[email protected]>  wrote:

I don't understand the logic behind TControl.Click:

procedure TControl.Click;
begin
    //DebugLn(['TControl.Click ',DbgSName(Self)]);
    if (not (csDesigning in ComponentState)) and (ActionLink<>  nil) and
       ((Action=nil) or (@FOnClick<>  @Action.OnExecute) or
Assigned(FOnClick)) then
      ActionLink.Execute(Self)
    else
    if Assigned(FOnClick) then
      FOnClick(Self);
end;


Maybe I overlook something, but
@FOnClick is the address of the variable holding the method reference (or nil)
so is @Action.OnExecute

So when can they ever be equal?

You are right.

Really?

AFAIK method pointers are handled differently in Delphi and FPC, where FPC requires @FOnClick to get the value stored in FOnClick, where Delphi guesses whether FOnClick should invoke the method or return the value.


Should that maybe compare FOnClick <> Action.OnExecute ?

That would miss difference in Data.
I added a CompareMem.

IMO the comparison worked as-is, as found in several places in the LCL.

What about:

function TControlActionLink.IsOnExecuteLinked: Boolean;
begin
  Result := inherited IsOnExecuteLinked
            and (FClient.OnClick = Action.OnExecute);
end;


Also is that supposed to be a shortcut, saving the call, or is that indeed supposed to modify behaviour?

Good question. I guess it would be enough to check (not (csDesigning in
ComponentState)) and (ActionLink <> nil).

Maybe the Delphi docs have an answer.

No :-(

Even if the 2 callbacks are pointing to the same method, calling Action.OnExecute, will call the callback with Sender=TheAction, while FOnClick gets the current object.

Looks as if Execute should be overridden in TControlActionLink!

DoDi


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

Reply via email to