Icon View Thread

The following is the text of the current message along with any replies.
Messages 1 to 6 of 6 total
Thread Anyone interested in a message queue?
Mon, Dec 5 2022 5:43 PMPermanent Link

Ralf Mimoun

Hi,

I am probably not the only one who needs something like easy-to-use events or message queues. Example: You change data in one form, and other forms should reflect these changes by reloading the data. Another one: I use classes derived from TPersistent or TCollection/TCollectionItem to read config data (something for another day, you define "sub configs", put them together like Lego, and then you can read it from a URL). When everything is loaded, I need a message to resume with the app.

So, I wrote a message queue. Object can subscribe to queues via name and unsubscribe (from one identified by name or from all queues). An object can push messages in the queue, and every subscriber will be notified.

There is a global object called MessageQueues, which makes the handling very simple. To subscribe to a queue, you just write

MessageQueues['MyQueue'].Subscribe(Self, ReceiveMethod);

"ReceiveMethod" is the method that is called by the queue for each message in that queue.

To send a message, you write

MessageQueues['MyQueue'].PushNew(Self);

You can use params, the definition is as follows:

procedure TMessageQueueItem.PushNew(Sender: TObject; StrValue: string = ''; IntValue: integer = 0; BoolValue: boolean = False);

Of course, there is more (like removing messages, check subscribers etc). It works like a charm and saves me tons of complicated code. I will need some hours to clean it up and add more remarks. Tell me if you are interested, and I'll upload it here.
Tue, Dec 6 2022 4:42 PMPermanent Link

erickengelke

Avatar

Ralf Mimoun wrote
:
> I am probably not the only one who needs something like easy-to-use events or message queues.

That's a brilliant idea.  Otherwise there is a tangled list of upcalls to make to synchronize pages.  

Erick
EWB Programming Books and Component Library
http://www.erickengelke.com
Tue, Dec 6 2022 10:00 PMPermanent Link

Steve Gill

Avatar

Hi Ralf,

I'm very interested!

= Steve
Thu, Dec 8 2022 5:53 PMPermanent Link

Ralf Mimoun

Ok, here it is. Have fun Smile



Attachments: MessageQueue.wbs
Fri, Dec 9 2022 3:49 AMPermanent Link

Walter Matte

Tactical Business Corporation

Thanks Ralf Mimoun!!!
Fri, Dec 9 2022 6:04 PMPermanent Link

Bill

Ralf, many thanks!
Image