Jump to content

web sockets update ClientSide. How to get the values from components from pascal code


VojkoCendak

Recommended Posts

Hi,

Websockets example full. The stringgrid is updated from websocket message event (ClientEvents...).

But if I want to read cell values from code values from cell[] are empty.

How can we get to the data in grid ?

The same problem is with any control that's updated from JavaScript.

thank you,

Vojko

 

Link to comment
Share on other sites

  • 1 month later...

I too have this question. The example does not seem to answer it - I think.

E.G. 

the Server module uses a websocket to update a client side unilabel caption, for example with a variable calculated in the server module ("filename"), like this

........

if PersistentNode then
    BroadcastMessage('update',
                             [
                               'value', filename
                             ],
                 [boClientOnly]);

....................

In the client main  we use the  clientevents to grab that message and update the label caption

function form.socketmessage(sender, msg, params, eOpts)
{
   if (msg == 'update') {
      MainForm.UniLabel1.setText(params.value);
   }
}

 

Visually the label does indeed update the caption to show the current value of "filename".

HOWEVER

      on the client side

showmessage(unilabel1.caption);    Shows the pre-existing caption NOT the updated text sent from the websocket.

 

What's the mechanism to update the internal representation of label.caption to match what's actually displayed?

Link to comment
Share on other sites

UPDATE:  Resolution - [well good enough anyway] - I'm sure it creates plenty of back and forth traffic - if anyone knows a better way then please dive in!

If the Websocket is used to update the text value of a UniEdit rather than a unilabel.caption then the Onchange event of that edit is fired and the uniedit.text  value is the new value sent by the websocket.

(N.B you need to use setValue from js to write the text field of a uniedit. )

( I tried with a dynamically created on change event for the label (as per the demo example dyn.dproj) but that never fired from the websocket update  - only manual changes)

So on the Client side we how have this js event

function form.socketmessage(sender, msg, params, eOpts)
{
   if (msg == 'update') {
     // MainForm.UniLabel1.setText(params.value);   << never updates the underlying value only the rendered one.
     MainForm.UniEdit1.setValue(params.value);    // Works fine
   }
}

Then use the standard Delphi/Unigui Onchange event of the UniEdit to get at the new value.

  • Thanks 1
Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...