[lazarus] Widget vs. Platform Independence

Stefan Hille stoppok at osibisa.ms.sub.org
Thu Sep 30 15:50:28 EDT 1999


On Thu, Sep 30, 1999 at 12:51:03PM -0400, Michael A. Hess wrote:
> Samuel Liddicott wrote:
> >  
> > Michael I am saying we should take the GTK callback handlers we now
> > have (you wrote them?) and have THEM call .wndproc instead of
> > .dispatch.
> The problem is, what wndproc does it call? Which control or component is
> it suppose to call? That is what dispatch does. It is a lower level RTL
> feature of all classes (objects). The dispatch routine is what routes
> the call to the correct control (object). In other words if you had a
> form with 3 buttons on it and a button click message was returned by a
> GTK button widget, which LCL button does it report to? The message from
> GTK doesn't know. All it contains is the Self pointer established when
> the LCL class was created. The only way it can send the message to the
> correct LCL control is to call dispatch which can determine from the
> table that FPC creates which LCL object should be called with the
> message.

That's no problem at all Michael. For example have a look at gtkTimerCB
which calls a procedure of the timer-object without using dispatch. (This
behaviuor was neccessary for some reason I can't remember now)
The only drawback I'm aware of is that it requires the TTimer.Timer
procedure to be a public member of the class.

A more elegant way of doing the same thing for each control could look
like this:

1. generic Message type for lmessages.pp

  TLM_WndProcMsg = record
     msg     : integer;
     realMsg : integer;
     userdata: pointer;

2. A class


  TControl = class (TComponent)
    constructor Create (aOwner : TComponent); override;  
    procedure  WindProc (var msg); message LM_WindProc;


  constructor TControl.Create (aOwner : TComponent);
     inherited Create (aOwner);
     SetCallback (LM_WindProc);

  procedure TControl.WindProc (var msg : TLM_WndProcMsg);
    // do the stuff & Dispatch

3. A callback

  Procedure SomeCallback (var widget; data : Pointer);
  var MessI : TLM_WndProcMsg;
      MessI.msg      := LM_WindProc;
      MessI.realMsg  := LM_SomeMessage;
      MessI.UserData := data;
      TObject (data).Dispatch (MessI);	

Another approach could be to make TControl.WindProc a function, and in the
callback we could the decide if we have to dispatch "realMsg" from also
from the callback or if windproc already did everthing;



PS: Reading this again I'm not sure if this approach works because I don't
    know if a message function can be virtual. Can it?
Stefan Hille          email: stoppok at osibisa.ms.sub.org 
48155 Muenster	      voice: 0251/664695 

More information about the Lazarus mailing list