Sign in Join

Live chat for Free Pascal, Lazarus, Delphi and every Pascal programmer.

Mailing lists / fpc-devel / 2007-02

procedure ... message

16 messages · 5 people · –

Reply by email Subscribe to this list Your subscription

Read-only archive. Use j and k to move between messages.

Michael Schnell

What does the compiler do when translating "procedure ... message" ?

I need to know this as I want to create a non-GUI workalike of the TApplication class that can do things like "TTimer" "TThread.Synchronize", Message events, etc, using Windows messages in Windows (for testing purpose) and system V message queues in Linux.

-Michael

Reply by email

peter green
to Michael Schnell
Show quoted text 6 lines
What does the compiler do when translating "procedure ... message" ? I need to know this as I want to create a non-GUI workalike of the TApplication class that can do things like "TTimer" "TThread.Synchronize", Message events, etc, using Windows messages in Windows (for testing purpose) and system V message queues in Linux.

afaict it does the same as delphi does, puts them in some form of table which is used by the dispatch method in tobject (which on delphi at least is called from wndproc which is called from mainwindowproc which is registered as the window procedure for the window and hence called by windows when the mainloop calls the windows api function dispatchmessage).

Reply by email

Michael Schnell
to peter green
peter green wrote 10 lines
> What does the compiler do when translating "procedure ... message" ? > > I need to know this as I want to create a non-GUI workalike of the > TApplication class that can do things like "TTimer" > "TThread.Synchronize", Message events, etc, using Windows messages in > Windows (for testing purpose) and system V message queues in Linux. > afaict it does the same as delphi does, puts them in some form of table which is used by the dispatch method in tobject (which on delphi at least is called from wndproc which is called from mainwindowproc which is registered as the window procedure for the window and hence called by windows when the mainloop calls the windows api function dispatchmessage).

Thanks a lot for your answer.

That is the result of what is happening. Most of it is done by the library (the compiler can't do this by itself), and I am trying to use some home-brew library functions here.

What I wanted to know is how the compiler does this (or how I can find out what exactly it does).

I _assume_ that when it sees "procedure ... message" the compiler in the "initialization" section generates a call to a library function that is supposed to register the message with the procedure. I need to know the name of this function so that I can do it in my new library.

I suppose in the end WidgetSet.AddEventHandler is called, but as the compiler does not know about a WidgetSet object that is created by the initialization of the RTL done by the library, I suppose some mechanism in the library is catching the stuff the compiler magic creates for "procedure ... message".

-Michael

Reply by email

Vincent Snijders
to Michael Schnell
Michael Schnell wrote 13 lines
peter green wrote: >> What does the compiler do when translating "procedure ... message" ? >> >> I need to know this as I want to create a non-GUI workalike of the >> TApplication class that can do things like "TTimer" >> "TThread.Synchronize", Message events, etc, using Windows messages in >> Windows (for testing purpose) and system V message queues in Linux. >> > afaict it does the same as delphi does, puts them in some form of table which is used by the dispatch method in tobject (which on delphi at least is called from wndproc which is called from mainwindowproc which is registered as the window procedure for the window and hence called by windows when the mainloop calls the windows api function dispatchmessage). > > Thanks a lot for your answer.

I see you are still a bit lost. Maybe the documentation can help: http://www.freepascal.org/docs-html/ref/refsu24.html

Vincent

Reply by email

Thorsten Engler
to Michael Schnell: Thanks a lot for your answer. That is the result of what is happening. Most of it is done…
>>>

That is the result of what is happening. Most of it is done by the library (the compiler can't do this by itself), and I am trying to use some home-brew library functions here.

What I wanted to know is how the compiler does this (or how I can find out what exactly it does).

I _assume_ that when it sees "procedure ... message" the compiler in the "initialization" section generates a call to a library function that is supposed to register the message with the procedure. I need to know the name of this function so that I can do it in my new library. <<<<

Your assumption is totally wrong. What happens is that the compiler creates an try in the message table of the RTTI for the class. Check out the implementation of Tobject.Dispatch to see how that is used.

Cheers,
Thorsten

Reply by email

Michael Schnell
to Vincent Snijders: I see you are still a bit lost. Maybe the documentation can help:…
I see you are still a bit lost. Maybe the documentation can help: http://www.freepascal.org/docs-html/ref/refsu24.html

I in fact am lost (as I still don't dare to try to look into the compiler's source code).

Unfortunately the docs text does not say what code the compiler generates to make the library assign the message to the function it generates from the users source code.

-Michael

Reply by email

Vincent Snijders
to Michael Schnell: I in fact am lost (as I still don't dare to try to look into the compiler's source code).…
Michael Schnell wrote 9 lines
> I see you are still a bit lost. Maybe the documentation can help: > http://www.freepascal.org/docs-html/ref/refsu24.html I in fact am lost (as I still don't dare to try to look into the compiler's source code). Unfortunately the docs text does not say what code the compiler generates to make the library assign the message to the function it generates from the users source code.

That is because the compiler doesn't generate that code.

Somewhere user code must call
   MyObject.Dispatch(MyMessage);

See implementation of dispatch. It gets the message number and looks for the corresponding method in a table. The compiler generates this table at compile time.

This may not be the completely accurate description, but this is how I model things in my mind and in my experiments reality hasn't falsified this model.

Vincent

Reply by email

Micha Nelissen
to Michael Schnell: Thanks. That seems to give me a clue. I have no idea what "creates a try" means but maybe…
Michael Schnell wrote 7 lines
> What happens is that the compiler creates > an try in the message table of the RTTI for the class. Check out the > implementation of Tobject.Dispatch to see how that is used. > Thanks. That seems to give me a clue. I have no idea what "creates a try" means but maybe I'll find out.

"creates an entry" most probably.

Micha

Reply by email

Michael Schnell
to Vincent Snijders: That is because the compiler doesn't generate that code. Somewhere user code must call…
See implementation of dispatch. It gets the message number and looks for the corresponding method in a table. The compiler generates this table at compile time.

Thanks. I did try to find it but am lost up till now. regarding Thorsten's message I assume it is a member function to some class (e.g. TObject), but my usual means to find such functions don't show it to me.

This may not be the completely accurate description, but this is how I model things in my mind and in my experiments reality hasn't falsified this model.

I do believe that you are right. Thorsten's hint that the compiler moves the information in the RTTI might point into the the correct direction, but up I still need to find out what the exactly RTTI contains and how to extract it from there.

-Michael

Reply by email

Michael Schnell
to Thorsten Engler: Should have been "an entry".
Thorsten Engler wrote
> Thanks. That seems to give me a clue. I have no idea what > "creates a try" means but maybe I'll find out. > Should have been "an entry"

Sorry for not guessing this :-\ .

Now I need to find out what exactly it puts into the RTTI and how to extract it from there.

Also I failed to find the implementation of TObject.Dispatch. Have you any hint where to search ?

Thanks again,
-Michael

Reply by email