eduardo.junqueira Posted July 20, 2016 Posted July 20, 2016 For instance, would pafina made in html and plain javascript , calling a unit method of Delphi , it is possible ? Quote
Sherzod Posted July 20, 2016 Posted July 20, 2016 Hi, If I understand you correctly, you can use ajaxRequest Best regards. Quote
eduardo.junqueira Posted July 20, 2016 Author Posted July 20, 2016 I did not understand. It would be something like Step 1 ====================== Unit xxx txxx.procyyy procedure ; begin run ggggg end ; step 2 ====================== page.html script javascript Call procedure txxx.procyyy ; the unit from html page Quote
Ron Posted July 20, 2016 Posted July 20, 2016 If I understand you correctly, you can then use a unihtmlframe and trigger an ajaxevent of that frame, from html, using ajaxRequest(mainform.htmlframe, ['eventname'], { param1: some_info }); and then handle that event and trigger the delphi procedure. Quote
eduardo.junqueira Posted July 20, 2016 Author Posted July 20, 2016 Would you please provide me a small example with sourceWould you please provide me a small example with source Quote
Sherzod Posted July 20, 2016 Posted July 20, 2016 Hi, Try, for example: 1. UniHTMLFrame1.HTML ... <input type="button" onclick="ajaxRequest(MainForm.UniHTMLFrame1, 'call', [])" value="call method '_click'"> 2. public { Public declarations } procedure _click; end; 3. procedure TMainForm.UniHTMLFrame1AjaxEvent(Sender: TComponent; EventName: string; Params: TUniStrings); begin if EventName = 'call' then begin _click; end; end; procedure TMainForm._click; begin ShowMessage('call'); end; Best regards. Quote
Sherzod Posted July 20, 2016 Posted July 20, 2016 Also you can search on the forum,there are many examples, including sending parameters Quote
eduardo.junqueira Posted July 20, 2016 Author Posted July 20, 2016 Okay , that part I understand . And when the page is external frame off what I need , there is this possibility ? Quote
Sherzod Posted July 20, 2016 Posted July 20, 2016 And when the page is external frame off what I need , there is this possibility ? Sorry, can you clarify ? Quote
eduardo.junqueira Posted July 20, 2016 Author Posted July 20, 2016 one page in php server for example running separately within this page call a delphi method of unigui app Quote
Sherzod Posted July 20, 2016 Posted July 20, 2016 I'm sorry I do not know how implemented your project, try adding the code above Quote
Ron Posted July 20, 2016 Posted July 20, 2016 Are you talking about loading an URL in an UrlFrame, and then trying to trigger any events in Unigui from that code? It seems to me that you then do not have access to the ajaxRequest function, so theoretically you could create a new XMLHttpRequest() object, if you only knew the URL on the unigui receiving side. <html> <head> </head> <body> <button type="button" onClick="xhr.send(encodeURI('eventname=test'));">Click Me!</button> <script type="text/javascript"> xhr = new XMLHttpRequest(); xhr.open('GET',encodeURI('[Unigui-urlframe-url]')); xhr.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded'); xhr.onload = function() { if (xhr.status === 200 && xhr.responseText !== newName) { alert('Something went wrong. Name is now ' + xhr.responseText); } else if (xhr.status !== 200) { alert('Request failed. Returned status of ' + xhr.status); } }; </script> </body> </html> Quote
Alessandro Posted September 19, 2016 Posted September 19, 2016 Hi, Try, for example: 1. UniHTMLFrame1.HTML ... <input type="button" onclick="ajaxRequest(MainForm.UniHTMLFrame1, 'call', [])" value="call method '_click'"> 2. public { Public declarations } procedure _click; end; 3. procedure TMainForm.UniHTMLFrame1AjaxEvent(Sender: TComponent; EventName: string; Params: TUniStrings); begin if EventName = 'call' then begin _click; end; end; procedure TMainForm._click; begin ShowMessage('call'); end; Best regards. Hi I tried to use the code, but does not work. Is there anything else to do? att, Quote
david600320@hotmail.com Posted April 20, 2017 Posted April 20, 2017 Hi , Delphi developer !! How are you ? I am testing of AjaxRequest() to get something on a Html file designed by bootstrap . BTW , I can't get any event from the html . I need your help !! > Delphi XE2 , Unigui 1.0.0.1386 , chrome latest After I put an uniHTMLFrame named HTMLFrame on the MainForm 1. HTMLFrame.HTML.LoadFromFile('index.html'); <----- designed html by bootstrap 2. added Five buttons for testing AjaxRequest() 3. added <script> function myfunc(){}</script> <!-- LOOK AT ME !! buttons for testing calling server ------------------------------------------------> - Two buttons works ! - <button type="button" class="btn btn-default" onclick="alert('OK'); ">alert</button> <button type="button" class="btn btn-default" onclick="javascript: myfunc('OK'); "> myfunc </button> - below Others not work for me - <button type="button" class="btn btn-default" onclick="ajaxRequest(MainForm.form , 'clickme', [] );" >call_form</button> <button type="button" class="btn btn-default" onclick="ajaxRequest(MainForm.window , 'clickme', [] );" >call_window</button> <button type="button" class="btn btn-default" onclick="ajaxRequest(MainForm.HTMLFrame , 'clickme', [] );">call_HTMLFrame</button> sg_dashboard.zip Best regards, David. Quote
Ron Posted April 20, 2017 Posted April 20, 2017 Hi David, In your code, you are loading an html file: procedure TMainForm.UniFormShow(Sender: TObject);begin HTMLFrame.HTML.LoadFromFile('index.html');end; And in this html file you have a redirect: <script language="javascript"> window.location.href = "pages/index.html"</script> So in effect you are kicked out of Unigui and the scope of the ajaxRequest function. If you change your onShow event to: procedure TMainForm.UniFormShow(Sender: TObject);begin HTMLFrame.HTML.LoadFromFile('pages/index.html');end;- you will stay in Unigui and catch the ajaxRequest. Rather load the correct html file into the HTMLFrame directly and adjust the paths to the other css and js files. Kaj Quote
david600320@hotmail.com Posted April 21, 2017 Posted April 21, 2017 Perfect !! , it works . Thank you so much Delphidude . 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.