How to pass String parameter to Notify() and receive that parameter to Notification()

Say for example, I use variable

LOC:Param1 STRING('hello')

I want to push a notify to a certain thread

NOTIFY(NOTIFY_NEW_MSG,GLOTHREAD:BGSERVICE,ADDRESS(LOC:Param1))

when i receive the event:notify using NOTIFICATION() command, how will i read the value of passed parameter hello? I tried checking the docs from clarion but I can’t find such answer. Thanks in advanced.

Look at the Clarion help for both NOTIFY and NOTIFICATION.

There are examples of both sides of the code there.

From NOTIFY

DynMenu.Construct  PROCEDURE()

  CODE
  SELF.NofWindows = 0
  NOTIFY (NOTIFY:Load, 1, ADDRESS (SELF.IDynMenu)) !Send Notify event to primary thread
  RETURN

From NOTIFICATION

  CASE EVENT()
  OF EVENT:Notify
     IF NOTIFICATION (NCode,, NParam) !NOTIFY has sent a Notify Event. Get Code and Parameter
     DM &= NParam + 0                !Assign passed parameter to reference var

     CASE Ncode                      !Test the Notify Code
     OF NOTIFY:Load
        DM.CreateMenu (Q)              !Execute appropriate action
     OF NOTIFY:Unload
       DO DestroyMenu
      UNLOAD ('DLL.DLL')             !Execute appropriate action
     END
   END

Basically NOTIFY lets you send a code to a thread with an optional parameter.

NOTIFY( notifycode, <thread>, <parameter> )

Then NOTIFICATION receives the values and you can parse them in the event loop.

NOTIFICATION(notifycode, <thread>, <parameter> )

Peek( NParam, Loc:AnotherMatchingVar )

You could also procedure overload and because you are using Address (var ) in the parameter you can prefix the parameter data type with an asterisk.

When you come to Peek the parameter or pass it by address, the first procedure needs to exist still in order to read the address.

Proc1( NParam )

Proc1( *String pVar )
Proc1( *Cstring pVar )
Proc1 *Long pVar )

Proc1( *String pVar )
code
Loc:String = pVar

The other caveat with using Notify/Notification is the buffer is First In Last Out, so be careful.

SendMessage is FIFO and I use that alot.

1 Like

Look at a &STRING reference and Reference Assignments

NString &STRING

OF EVENT:Notify
    IF NOTIFICATION (NCode,, NParam)
      NString &= (NParam)

IIRC you may have trouble with that local variable that is on the stack, it may need to be created with NEW so it is on the heap.


For something as simple as your example it would be better to setup Equates and use numbers:

BlargNotify Itemize,Pre()
BlargNotify:Hello EQUATE 
     END
2 Likes

Thanks guys, I have tried using PEEK() which worked for me.