Jump to content

Mixing JS calls with pascal code


paul.coshott

Recommended Posts

Hi All,

I've just learned how to change the background color of a panel using client side JS in the ClientEvents property :). Works great (thanks Sherzod).

But I also have another case where I am changing the background color of a panel (and one where I change the background color of a label), but the color it changes to depends on quite a few factors and also whether it was previously selected or not selected.

So what I'm asking, is can I call JS code from within my pascal coded events. And if I can, how do I do this? An example of changing the background color of an object would be great.

Thanks,
Paul

Delphi 10.2 Pro, uniGUI 1.9.0.1502 Complete Professional, Windows 10 Pro

Link to comment
Share on other sites

1 hour ago, paul.coshott said:

So what I'm asking, is can I call JS code from within my pascal coded events. And if I can, how do I do this? An example of changing the background color of an object would be great.

Hi,

Well, if you use a code on the server side, it is better to use pascal code.

Or you can use the object's JSInterface property.

JSInterface.JSCall()
JSInterface.JSCallDefer()
...

 

Link to comment
Share on other sites

2 hours ago, paul.coshott said:

Thanks for the info. Could you give me an example of using the JSInterface to change the background color of a panel?

  UniPanel1.Color := clGreen;
  UniPanel1.JSInterface.JSCall('setBodyProp', ['background-color','green']);
  UniPanel1.JSInterface.JSCall('setBodyProp', ['background-color','#008000']);
  UniPanel1.JSInterface.JSCall('setBodyProp', ['background-color', uniColor2Web(clGreen)]); //uses ... uniGUIJSUtils;

 

Link to comment
Share on other sites

Hi Sherzod,

Thanks for the example. It worked fine, but it was no faster than the pascal code.

So, next question. Is it possible to fire a java script event from within the pascal code, that will cause the background color to change quicker?

Cheers,
Paul

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...