Sign in Join

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

Mailing lists / fpc-devel / 2009-10

New global CustomApplication variable

27 messages · 5 people · –

Reply by email Subscribe to this list Your subscription

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

Joost van der Sluis

Hi all,

In fpc 2.5.1 I've introduced the global CustomApplication variable in the custapp unit. The idea is that when this variable is set when a application-object is initialized, this variable is set so that you can access the CustomApplication-object without knowing in which unit it is defined.

We've discussed this before.

I want to know if the current implementation is usefull for the existing application-frameworks like Lazarus and MSEIde. If that's so I'll maybe merge it to fpc 2.3.1.

Joost.

Reply by email

Martin Schreiber
to Joost van der Sluis
Joost van der Sluis wrote 5 lines
I want to know if the current implementation is usefull for the existing application-frameworks like Lazarus and MSEIde. If that's so I'll maybe merge it to fpc 2.3.1.

MSEide has its own implementation of
tcustomapplication/tapplication/tguiapplication with a similar approach.

Martin

Reply by email

Michael Schnell
to Joost van der Sluis: In fpc 2.5.1 I've introduced the global CustomApplication variable in the custapp unit.…

IIRC, the TApplication instance needs to take care of the message queue that schedules events for TTimer the Delphi "procedure ... message" construct etc.

With GUI application the message queue is managed by means of the appropriate GUI Framework, such as the Windows or GTK API-

MSE provides creating a "nogui" application that handles the message queue without complex external stuff but in Linux uses "sem_wait()" to wait in case of an empty message queue and signals for posing events. (I don't know how they do this in Windows).

I feel that this would be a very appropriate extension to the native FPC RTL, so that IDE frameworks can standardize on this.

-Michael

Reply by email

Martin Schreiber
to Michael Schnell
Michael Schnell wrote 5 lines
MSE provides creating a "nogui" application that handles the message queue without complex external stuff but in Linux uses "sem_wait()" to wait in case of an empty message queue and signals for posing events. (I don't know how they do this in Windows).

MSEgui sem_wait() is platform independent. Because on Windows terminate and timer events must be caught also, msgwaitformultipleobjects() will be used.

Martin

Reply by email

Joost van der Sluis
to Martin Schreiber: MSEide has its own implementation of tcustomapplication/tapplication/tguiapplication with…
Martin Schreiber wrote 8 lines
On Thursday 08 October 2009 17:36:44 Joost van der Sluis wrote: > > I want to know if the current implementation is usefull for the existing > application-frameworks like Lazarus and MSEIde. If that's so I'll maybe > merge it to fpc 2.3.1. > MSEide has its own implementation of tcustomapplication/tapplication/tguiapplication with a similar approach.

Yes, offcourse. But the idea is to unify this. So that you can access the CustomApplication without knowing if you are using Lazarus or MDEide. So can you set the global CustomApplication variable in MSEIde, so it's also accessible for other units?

Joost

Reply by email

Michael Schnell
to Joost van der Sluis
Joost van der Sluis wrote
YBut the idea is to unify this.

This is what I meant, too.

I feel that MSEIDE/MSEGUI is quite advanced regarding the (flexibility of) the TApplication implementation, and thus, who wants to modify/enhance the implementation of the "Application" thingy in FPC (RTL) itself, should take a look at MSEIDE/MSEGUI and ask Martin tor some suggestions.

-Michael

Reply by email

Martin Schreiber
to Joost van der Sluis: Yes, offcourse. But the idea is to unify this. So that you can access the…
Joost van der Sluis wrote 8 lines
> MSEide has its own implementation of > tcustomapplication/tapplication/tguiapplication with a similar approach. Yes, offcourse. But the idea is to unify this. So that you can access the CustomApplication without knowing if you are using Lazarus or MDEide. So can you set the global CustomApplication variable in MSEIde, so it's also accessible for other units?

MSEgui has functions which return a singleton of the application instance. msegui.application function returns a tguiapplication, msenogui.application function a tnoguiapplication, both inherit from MSEgui tcustomapplication which is independent from FPC TCustomApplication, MSEgui application object implementation is incompatible to FPC I fear.

Martin

Reply by email

Joost van der Sluis
to Martin Schreiber
Martin Schreiber wrote 15 lines
On Monday 12 October 2009 17:09:42 Joost van der Sluis wrote: > > MSEide has its own implementation of > > tcustomapplication/tapplication/tguiapplication with a similar approach. > > Yes, offcourse. But the idea is to unify this. So that you can access > the CustomApplication without knowing if you are using Lazarus or > MDEide. So can you set the global CustomApplication variable in MSEIde, > so it's also accessible for other units? > MSEgui has functions which return a singleton of the application instance. msegui.application function returns a tguiapplication, msenogui.application function a tnoguiapplication, both inherit from MSEgui tcustomapplication which is independent from FPC TCustomApplication, MSEgui application object implementation is incompatible to FPC I fear.

Ok, that's clear. In that case this global variable is useless for MSEgui.

But why don't you use fpc's TCustomApplication? Can we improve it so that you could use it?

Joost

Reply by email

Martin Schreiber
to Joost van der Sluis
Joost van der Sluis wrote
But why don't you use fpc's TCustomApplication? Can we improve it so that you could use it?

I need functionality from tmsecomponent which is difficult to achieve if I would inherit from FPC TCustomApplication, although not impossible. Another Problem is Delphi compatibility, I'll have a look.

Thanks, Martin

Reply by email

Michael Schnell
to Martin Schreiber
Martin Schreiber wrote
I'll have a look.

Great !

I'd appreciate having a common TApplication paradigm with FPC from which both MSEGUI and Lazarus (and whatever) can inherit from and that supports all GUI frameworks and non-GUI stuff and remote WEB-interface.

-Michael

Reply by email

Michael Van Canneyt
to Michael Schnell
Michael Schnell wrote 8 lines
Martin Schreiber wrote: > I'll have a look. Great ! I'd appreciate having a common TApplication paradigm with FPC from which both MSEGUI and Lazarus (and whatever) can inherit from and that supports all GUI frameworks and non-GUI stuff and remote WEB-interface.

It exists and is implemented in custapp since years for exactly this reason.

Michael.

Reply by email

Michael Schnell
to Michael Van Canneyt
Michael Van Canneyt wrote 7 lines
It exists and is implemented in custapp since years for exactly this reason.

Fine,
But then the OP's should already have what he needs needs ...

Do in fact Lazarus and MSEGUI use this in the way it is intended ?

A request now might be that the FPC RTL offers a non-gui implementation of a message queue that works directly on the system API of the supported OSes to allow for events like those that are thrown by things like TTimer and TThread.synchronize or to be captured by a construct like "procedure ... message". Here MSEGUI on Linux implements something based on Signals. (On Windows it supposedly is based on Windows Messages.)

I feel that something like would be worth being provided in the more "general" FPC distribution.

-Michael

Reply by email

Marco van de Voort
to Michael Schnell

In our previous episode, Michael Schnell said:

Show quoted text 11 lines
Fine, But then the OP's should already have what he needs needs ... Do in fact Lazarus and MSEGUI use this in the way it is intended ? A request now might be that the FPC RTL offers a non-gui implementation of a message queue that works directly on the system API of the supported OSes to allow for events like those that are thrown by things like TTimer and TThread.synchronize or to be captured by a construct like "procedure ... message". Here MSEGUI on Linux implements something based on Signals. (On Windows it supposedly is based on Windows Messages.)

That's an attempt on emulating something that is not really portable.

There are a handful of signal and thousands of possible windows messages. Moreover, windows messages contain state about the owner.

Reply by email

Michael Van Canneyt
to Michael Schnell: But then the OP's should already have what he needs needs ... Do in fact Lazarus and…
Michael Schnell wrote 13 lines
Michael Van Canneyt wrote: > > > It exists and is implemented in custapp since years for exactly this > reason. > > Fine, But then the OP's should already have what he needs needs ... Do in fact Lazarus and MSEGUI use this in the way it is intended ?

Lazarus certainly does.

Show quoted text 10 lines
A request now might be that the FPC RTL offers a non-gui implementation of a message queue that works directly on the system API of the supported OSes to allow for events like those that are thrown by things like TTimer and TThread.synchronize or to be captured by a construct like "procedure ... message". Here MSEGUI on Linux implements something based on Signals. (On Windows it supposedly is based on Windows Messages.) I feel that something like would be worth being provided in the more "general" FPC distribution.

Feel free to contibute a descendent of TCustomApplication that adds a message queue. Personally, I don't see the need, but I can imagine that someone does.

I say a descendent of TCustomApplication because I don't think it belongs in TCustomApplication itself, because not all applications need a message queue.

Michael.

Reply by email

Michael Schnell
to Marco van de Voort: In our previous episode, Michael Schnell said: That's an attempt on emulating something…
Marco van de Voort wrote 5 lines
That's an attempt on emulating something that is not really portable. There are a handful of signal and thousands of possible windows messages. Moreover, windows messages contain state about the owner.

Of course this is true for the original Delphi "procedure ... message", which would need to be replaced by some portable (inter-thread) messaging mechanism. IIRC, this is already available on Lazarus and/or MSEGUI,

But for TThread-synchronize and TTimer the implementation dependent details are hidden in the appropriate TApplication code, anyway, so no portability problem here.

-Michael

Reply by email

Marco van de Voort
to Michael Schnell

In our previous episode, Michael Schnell said:

Show quoted text 8 lines
Of course this is true for the original Delphi "procedure ... message", which would need to be replaced by some portable (inter-thread) messaging mechanism. IIRC, this is already available on Lazarus and/or MSEGUI, But for TThread-synchronize and TTimer the implementation dependent details are hidden in the appropriate TApplication code, anyway, so no portability problem here.

Well, the point is if it really is compatible. And the other consideration is that such system should eat resources that are scarce (like SIGUSR and SIGUSR2)

Reply by email

Michael Schnell
to Michael Van Canneyt: Lazarus certainly does. Feel free to contibute a descendent of TCustomApplication that…
Michael Van Canneyt wrote
Feel free to contibute a descendent of TCustomApplication that adds a message queue.

I don't suppose this can decently and portable and tested for all available archs and OSes be done in just a few hours :)

It (a non-gui depending TApplication that works without any GUI binding) seems to be available with MSEGUI. So it would be viable to ask Martin to provide it.

Personally, I don't see the need, but I can imagine that someone does.

I definitely will use it some day. I am already planing this (embedded) project since long.

I would use the MSE1-GUI sources if I start the project, but it I just can use the RTL for that purpose, some complexity would be avoided.

I say a descendent of TCustomApplication because I don't think it belongs in TCustomApplication itself, because not all applications need a message queue.

I of course do agree. I don't remember if MSEGUI does it this way, but I feel it would be the most straight forward implementation method.

-Michael

Reply by email

Michael Schnell
to Marco van de Voort: In our previous episode, Michael Schnell said: Well, the point is if it really is…
Marco van de Voort wrote
Well, the point is if it really is compatible. And the other consideration is that such system should eat resources that are scarce (like SIGUSR and SIGUSR2)

I never worked with signals up to now.

Martin once told me that the MSEGUI implementation of the message queue does use signals. Maybe there are other primitives in Linux that are not that scarce Do you think, (e.g.) System V message queues would be more appropriate ?

-Michael

Reply by email

Marco van de Voort
to Michael Schnell

In our previous episode, Michael Schnell said:

Show quoted text 10 lines
> Well, the point is if it really is compatible. And the other consideration > is that such system should eat resources that are scarce (like SIGUSR and > SIGUSR2) I never worked with signals up to now. Martin once told me that the MSEGUI implementation of the message queue does use signals. Maybe there are other primitives in Linux that are not that scarce Do you think, (e.g.) System V message queues would be more appropriate ?

Afaik, at the time when I was researching this (mass async messagehandling), this was discounted because FreeBSD didn't support them (*)

I then gave up emulating the windows messaging concept because while you might be able to emulate a few cases, you could not reliably implement it crossplatform (cross-unix actually).

(*) it did support them, but it was turned off in default kernels, and the
status was not exactly known, so for all practical purposes they weren't.

But maybe you could do some research on the subject.

Reply by email

Martin Schreiber
to Michael Schnell: I never worked with signals up to now. Martin once told me that the MSEGUI implementation…
Michael Schnell wrote
Martin once told me that the MSEGUI implementation of the message queue does use signals.

???
The MSEgui *timer* system on Linux works with SIGALRM. The eventqueue is implemented on all platforms, with and without GUI as an internal teventlist which holds instance pointers of tevent class. The X and win32 events are packed into a appropriate tevent descendent and feed into the queue. It is possible to loop tevent's to X or win32 event queue if the receiving order must be synchronized with system events.

Martin

Reply by email

Michael Schnell
to Martin Schreiber
Martin Schreiber wrote 5 lines
The eventqueue is implemented on all platforms, with and without GUI as an internal teventlist which holds instance pointers of tevent class. The X and win32 events are packed into a appropriate tevent descendent and feed into the queue. It is possible to loop tevent's to X or win32 event queue if the receiving order must be synchronized with system events.

GREAT !

This seems to be platform and GUI system independent and thus is exactly how I think it should be done.

I feel it would be a very desirable enhancement to the FPC RTL if this would be moved there and any GUI-based "TApplication"(such as coming with MSEGUI and Lazarus) and any non-GUI-based "TApplication" (such es "embedded" stuff and remote GUIs such as HTTP based "Bowser-GUI" implementations) would be built on top of this.

-Michael

Reply by email

Michael Schnell
to Martin Schreiber: ??? The MSEgui *timer* system on Linux works with SIGALRM. The eventqueue is implemented…

Martin Schrieffer wrote

The eventqueue is implemented on all platforms, with and without GUI as an internal teventlist which holds instance pointers of tevent class.

Important additional Question:

How is a work alike to Delphi's "procedure .... message" construct done, which can be used to signal a state change from a thread towards the main thread ?

( Very low pitched additional question:
Does this mechanism allow for installing multiple such event queues in order to allow for some thread to each have its own event queue ? (A dream of mine since years :) )
)

Reply by email