[lazarus] Latest source is attached.
Michael A. Hess
mhess at miraclec.com
Sat Jul 3 15:51:34 EDT 1999
Shane Miller wrote:
>
> Now I'm confused. Got any working example code?
Let me give you the simple explaination.
In objpas of the RTL which defines TObjects there is a method called
DispatchStr. When you setup a procedure in your class using,
procedure something(self : thisClass); message 'show';
the compiler adds this method to a table and cross references it to the
string 'show'. When you call DispatchStr for a given component that
inherited from TObject (which everything does) and pass it the message
such as:
Dispatch('show');
The object goes through the table, finds the matching message, and then
calls the method indicated in the table.
So what I am doing is setting up the messages for the various components
such as the TForm example in my previous email.
procedure DoShow(Self : TCustomForm); message 'show';
Then in the Create I call:
GUIAPI_Callback('show', Self);
Now in the GUIAPI_Callback it determines what kind of message needs to
be handled. In this case it is a 'show' message.
For every type of message possible there is a separate routine that is
used as the callback from gtk.
procedure GUIAPI_Callback(signal : string, Sender : TControl);
var
gObject : gtk_Object;
signalFunc : Pointer;
gSignal : array[0..15] of char;
begin
.
.
.
gObject := gtk_Object(Sender.fcomponent);
if signal = 'show' then
signalFunc = @gtkshowCB;
.
.
.
gtk_signal_connect(gObject, gSignal, gtk_Signal_Func(signalFunc),
Sender);
end;
When the above function sees the 'show' message it knows to setup the
callback to gtkshowCB and it passes Self as the data.
So now you need to write the gtkshowCB. It looks like this
function gtkshowCB(widget: PGtkWidget; data: gPointer):Boolean;cdecl;
begin
TControl(data).GUIAPI_Signals('show', TControl(data));
end;
Every 'show' message callback from gtk, no matter what component, will
go through here. It uses the data value which points to Self which is
the actual control that needs to receive the message. Every component is
based on TControl so in that class I create the GUIAPI_Signals method.
It then looks like this.
procedure TControl.GUIAPI_Signals(signal : string, obj : TControl);
begin
DispatchStr(signal);
end;
At this point the message is of to the appropriate control and should be
handled as you wish.
Now this is how I have it all setup in code and it wasn't quite working
before but that was due to the fact that various aspects of the compiler
namely some of the pointer stuff wasn't working right. I believe that it
should work now since it has been stated that it has been corrected.
I don't have clean code to send at this point since I was kludging
around in the code as it WAS about 6 weeks ago. I have gotten fresh code
out of CVS and will add this to the current code and try and compile and
see if it works.
Does that make it clearer?
I will send you the code as soon as I have it working.
--
==== Programming my first best destiny! ====
Michael A. Hess Miracle Concepts, Inc.
mhess at miraclec.com http://www.miraclec.com
More information about the Lazarus
mailing list