Harry Rogers Posted May 16, 2016 Posted May 16, 2016 HI What's the syntax for calling a Delphi function or procedure from JS ? When some condition is met in the Javascript I want to call a delphi procedure, from the Clientevents demos it's easy to see setting text and moving elements around the form but I can't see calling a delphi procedure. Here is a simple delphi procedure procedure TMainForm.btnMaskClick(Sender: TObject); begin bMasked := true; frmmask.ShowModal(); end; ........ and some JS in the script property of the form ...... ...... if (_MaxTry >= MAX_COUNT) { MainForm.lblWarning.setText('You have used all attempts'); << works fine MainForm.lblStatus.setPosition(x,y); << works fine MainForm.btnMaskClick(self); <<<< this is the one I don't know the syntax of } Many thanks Harry Quote
bugra Posted May 16, 2016 Posted May 16, 2016 Hi You can create ajax request. For example in some component's click clientevents there is this code bellow function click(sender, e, eOpts) { var time = 0; for (i=0;i<=5000;i++) { time +=1; MainForm.UniButton1.setText(time); } if (time >= 5000) { ajaxRequest(MainForm.UniButton1, 'SomeRequestNamedByMe', []); } } and in onAjaxEvent there is this code procedure TMainForm.UniButton5AjaxEvent(Sender: TComponent; EventName: string; Params: TUniStrings); begin if EventName='SomeRequestNamedByMe' then begin myProcedure; end; end; First call ajaxRequest in JS when condition is true. Second one call procedure named myProcedure in delphi. Quote
Harry Rogers Posted May 16, 2016 Author Posted May 16, 2016 OK great - got that. I was coming to the same conclusion (slowly!) Many Thanks All the best Quote
bugra Posted May 16, 2016 Posted May 16, 2016 also you can send a parameter in ajaxRequest like ajaxRequest(MainForm.UniButton1, 'SoneRequest', ['Time='+time]); and call it in delphi someString := Params.Values['Time']; Quote
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.