[Lazarus] TControl.Click?

Mattias Gaertner nc-gaertnma at netcologne.de
Sat Oct 1 15:18:18 CEST 2011


On Sat, 01 Oct 2011 15:43:34 +0200
Hans-Peter Diettrich <DrDiettrich1 at aol.com> wrote:

> Mattias Gaertner schrieb:
> > On Sat, 01 Oct 2011 08:39:42 +0100
> > Martin <lazarus at mfriebe.de> wrote:
> > 
> >> On 01/10/2011 07:53, Mattias Gaertner wrote:
> >>> On Sat, 01 Oct 2011 03:04:56 +0200
> >>> Hans-Peter Diettrich<DrDiettrich1 at aol.com>  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, 

No.
You could say: Method pointers are handled differently in mode Delphi
and mode ObjFPC.
And since the LCL uses mode objfpc the @event is unambiguous and
therefore wrong as Martin wrote.


>[...]
> >> 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);

Thanks for pointing out.
Fixed by using CompareMethods.


> 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 :-(

It seems Delphi calls OnClick when it is set and differs from the
Action. I did that.

 
> >> 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!

Why? How?

Mattias




More information about the Lazarus mailing list