Jump to content

Recommended Posts

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

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.

Posted

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.

 

Posted

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> 
  • 1 month later...
Posted

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,
  • 7 months later...
Posted

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>
 
Best regards,
David.
Posted

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
 

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