PC SOFT

FORUMS PROFESSIONNELS
WINDEVWEBDEV et WINDEV Mobile

Accueil → WINDEV 2024 → Custom Event + Custom Event Args
Custom Event + Custom Event Args
Débuté par Andrew, 24 sep. 2014 21:39 - 8 réponses
Posté le 24 septembre 2014 - 21:39
Hi there!

Any chance I can create/send my own arguments for events?

It seems like all I'm able to do is create an event (Event(EventName, control, ProcedureOnEvent)) and then to call that event I'm only allowed SendMessage() or PostMessage()... which only allows 3 parameters -- all integers.

I've got a custom event that needs a non-integer argument to deal with it more precisely. I already created a global variable of a structure with the required data and just passed a pointer (integer!) when calling SendMessage() or PostMessage() but WOW if that's the best solution I'm pretty nervous about what other junk I'll have to come up with while dealing with WinDev.

I'm sure there's something I'm missing but I can't seem to find it. Any help is much appreciated!
Posté le 25 septembre 2014 - 11:59
Hi Andrew

that is not a windev problem. In this case, windev is just offerring the
regular SendMessage/postMessage functions straight from the APIs.

Furthermore, if you look at any windows message, you'll see the same
thing, with 'complex' information passed by address...

Now the question is, IMHO, what do you need sendMessage/postMessage for?
Because that is NOT a very often used functions, that's for sure, and
there may be a much easier way to do what you need, IF you tell us what
that is, of course.

Best regards


--
Fabrice Harari
Consultant WinDev, WebDev et WinDev Mobile International

NOUVEAU: WXReplication, votre système de réplication open source est
disponible sur mon site web !!!
WXShowroom.com : Montrez vos projets !
Plus d'information sur http://fabriceharari.com


On 9/24/2014 1:39 PM, Andrew wrote:
Hi there!

Any chance I can create/send my own arguments for events?
It seems like all I'm able to do is create an event (Event(EventName,
control, ProcedureOnEvent)) and then to call that event I'm only allowed
SendMessage() or PostMessage()... which only allows 3 parameters -- all
integers.

I've got a custom event that needs a non-integer argument to deal with
it more precisely. I already created a global variable of a structure
with the required data and just passed a pointer (integer!) when calling
SendMessage() or PostMessage() but WOW if that's the best solution I'm
pretty nervous about what other junk I'll have to come up with while
dealing with WinDev.

I'm sure there's something I'm missing but I can't seem to find it. Any
help is much appreciated!
Posté le 25 septembre 2014 - 13:36
Ah sweet, thanks!


I've got a thread running in the background -- runs for a while - typically ~1 minute. As the thread completes certain steps (let's say there are 10 steps) the completion of the step throws up its event and whatever windows are listening for that event catch it and respond accordingly (the behaviour here would be determined by the event arguments) -- and on their own thread (that's a wee bit important).

What's great about the events is that the thread can just worry about its own stuff - it doesn't have to know who/what needs to be updated - it only needs to shout out to the world that Step 1 is done, now Step 2 is done, now Step 3 is done, and so on and whoever wants to listen can listen. And that's what I appreciated about PostMessage() -- just post it, then keep on truckin'.
Posté le 25 septembre 2014 - 14:36
Hi Andrew

this is what I do in this case: I create an associative array in memory...

My thread is therefore adding a line in the array (with a unique INT ID
as the index)... it can then do its postmessage and send as parameter
the unique INT ID.

Anybody/anything/AnyWindow concerned by the post message just has to
read in the array, do what's needed, and most of the time delete the
array line...

Best regards

--
Fabrice Harari
International WinDev, WebDev and WinDev mobile Consulting

NEW: WXReplication, your open source replication system is available on
my web site!!!
WXShowroom.com: Show your projects!
More information on http://www.fabriceharari.com


On 9/25/2014 5:36 AM, Andrew wrote:
Ah sweet, thanks!


I've got a thread running in the background -- runs for a while -
typically ~1 minute. As the thread completes certain steps (let's say
there are 10 steps) the completion of the step throws up its event and
whatever windows are listening for that event catch it and respond
accordingly (the behaviour here would be determined by the event
arguments) -- and on their own thread (that's a wee bit important).

What's great about the events is that the thread can just worry about
its own stuff - it doesn't have to know who/what needs to be updated -
it only needs to shout out to the world that Step 1 is done, now Step 2
is done, now Step 3 is done, and so on and whoever wants to listen can
listen. And that's what I appreciated about PostMessage() -- just post
it, then keep on truckin'.
Posté le 25 septembre 2014 - 15:37
Cool!

Now how would I make that so that I could have multiple listeners for the same event? -- if one window reacts to the event (thus, removing the item from the array) before another window's queue is able to react, then I may be a little SOL as the other window won't have the arguments. Each window/listener would require its own global array. Now, that could work -- until I get 10 instances of the same window. Now I'm not only posting a message using the unique handle for each window/listener (this is what I'm currently doing - LOVE it), I'm also forced to alias each window so that I can target each window's global array BEFORE posting the event.

Is my thinking correct? -- maybe I'm over-thinking it?
Posté le 25 septembre 2014 - 16:13
Hi again

you could have one array per window, of course, but it seems to me that
it would be easier to use only ONE EXTRA array to record "DONE" status.

In that case, you would the main array for the communication, and each
secondary process would write in the secondary array a new record when
done processing. By example:
- Array ID is 23.
- You have 10 windows, each with a specific alias
- when each window is done processing, it adds in the secondary array
23-MyAlias
- it then checks if ALL windows have added that record, if yes, delete
the main record, delete the 10 done records, and that's it
- of course, each window, when opening, would have to register its alias
in a central place, so that the verification of DONE status for all
windows could be done dynamically, no matter how many windows are open.

Best regards

--
Fabrice Harari
International WinDev, WebDev and WinDev mobile Consulting

NEW: WXReplication, your open source replication system is available on
my web site!!!
WXShowroom.com: Show your projects!
More information on http://www.fabriceharari.com


On 9/25/2014 7:37 AM, Andrew wrote:
Cool!

Now how would I make that so that I could have multiple listeners for
the same event? -- if one window reacts to the event (thus, removing the
item from the array) before another window's queue is able to react,
then I may be a little SOL as the other window won't have the arguments.
Each window/listener would require its own global array. Now, that could
work -- until I get 10 instances of the same window. Now I'm not only
posting a message using the unique handle for each window/listener (this
is what I'm currently doing - LOVE it), I'm also forced to alias each
window so that I can target each window's global array BEFORE posting
the event.
Is my thinking correct? -- maybe I'm over-thinking it?
Posté le 25 septembre 2014 - 16:45
Very interesting!

Just to make sure I understand...

One global associative array (dictionary) (project-wide scope) with a key of string (the event name).
Its value is a structure with another dictionary which has a key of integer (handles of listeners) and a value of variant (the events' argument). Once the listener has handled the event I remove that event's handle's element.

It will be interesting to see what happens when I run 10 instances of this thread that I'm talking about and the event fires 10 times at approximately the same time -- I may need a Guid (global unique identifier) to make sure that each one gets handled correctly and that the arguments don't just overwrite each other.

Anyway - I'll put it into practice and see what happens!


Thank you very much for your time, eh!
Posté le 25 septembre 2014 - 18:22
Hi Andrew

that may work, but that is NOT what I described at all...

In my solution, you have two arrays. The first one has a UNIQUE per
process ID (GUID, by example, or integer), the second has that
ID+WindowsAlias

One is NOT inside the other

Best regards


--
Fabrice Harari
Consultant WinDev, WebDev et WinDev Mobile International

NOUVEAU: WXReplication, votre système de réplication open source est
disponible sur mon site web !!!
WXShowroom.com : Montrez vos projets !
Plus d'information sur http://fabriceharari.com


On 9/25/2014 8:45 AM, Andrew wrote:
Very interesting!

Just to make sure I understand...

One global associative array (dictionary) (project-wide scope) with a
key of string (the event name).
Its value is a structure with another dictionary which has a key of
integer (handles of listeners) and a value of variant (the events'
argument). Once the listener has handled the event I remove that event's
handle's element.
It will be interesting to see what happens when I run 10 instances of
this thread that I'm talking about and the event fires 10 times at
approximately the same time -- I may need a Guid (global unique
identifier) to make sure that each one gets handled correctly and that
the arguments don't just overwrite each other.

Anyway - I'll put it into practice and see what happens!


Thank you very much for your time, eh!
Posté le 29 septembre 2014 - 13:01
Got it working - does the job not half bad!

Now... do we have any namespacing capabilities in WinDev? Or am I stuck with this BS alphabetically sorted list of packages/classes/procedures?