Recent

Author Topic: Lazarus - Webkit - evaluateJavaScript access violation  (Read 3639 times)

arximidis

  • New Member
  • *
  • Posts: 25
Lazarus - Webkit - evaluateJavaScript access violation
« on: September 08, 2013, 03:27:22 pm »
Hello

I am encountering a problem with webkit on Lazarus qt

When I try to execute a JavaScript function with evaluateJavaScript, I get an access violation error if I don't trap, with try - except
Of course, I call the function when DOM has already been created

Example

freepascal code:
Code: [Select]
          param:='Hello';
          parameter:=Format('foo("%s")',[param]);
          QWebFrame_evaluateJavaScript(QWebFrame,nil,@parameter);

javascript code:
Code: [Select]
function foo(param){
  alert(param);
}

I am always getting an access violation error and the whole application crashes



But if I trap like this:
Code: [Select]
   try
          param:='Hello';
          parameter:=Format('foo("%s")',[param]);
          QWebFrame_evaluateJavaScript(QWebFrame,nil,@parameter);
  except
     //trap errors
  end;

everything is working as it should, with no errors and crashes




However I am not satisfied with this solution because I am bypassing the problem. Does anybody know about this?

Thank you
« Last Edit: September 08, 2013, 03:31:52 pm by arximidis »

mercury

  • Full Member
  • ***
  • Posts: 154
Re: Lazarus - Webkit - evaluateJavaScript access violation
« Reply #1 on: July 30, 2015, 03:47:13 pm »
I'm working on something similar.
Here is my code
Code: [Select]
var
  QWebFrame: QWebFrameH;

  script: WideString;
  retval: QVariantH;
  retvalS: WideString;
begin
  QWebFrame := QWebPage_mainFrame(QWebView_page(WebView));
  script := Utf8ToAnsi('foo("Hello 哇嘎嘎")');
  retval := QVariant_create;
  QWebFrame_evaluateJavaScript(QWebFrame, retval, @script);
  QVariant_toString(retval, @retvalS);
  retvalS := AnsiToUtf8(retvalS);
  ShowMessage('retval : ' + #10 + retvalS + ' ');
end;
It's no access violation error.

on the other hand
I'm finding a way of javascript call pascal function with retval.
Any idea?
« Last Edit: July 30, 2015, 03:49:05 pm by mercury »

 

TinyPortal © 2005-2018