https://groups.google.com/forum/?fromgroups#!searchin/delphichromiumembedded/js$20value|sort:relevance/delphichromiumembedded/uDxAUTvXqzc/fYR1wlvvUY8J
 
Call Delphi from Javascript in TChromium Component
10 名作者发布了 13 个帖子
 
 
Mark Di Val 
12/11/13
Hi All,
 
Apologies if this has already be done to death somewhere else - but I can't find a way to do this.
 
I can set events in my javascript (Google Maps API v3 events) which will run a js function.
 
What I would like to be able to do is call a Delphi function or procedure passing a string parameter.
 
TIA
 
Mark
 
 
 
 
Mark Di Val 
12/11/13
BTW I notice that this code never gets called - seems fairly critical!
 
procedure TCustomRenderProcessHandler.OnWebKitInitialized;
begin
{$IFDEF DELPHI14_UP}
  TCefRTTIExtension.Register('app', TTestExtension);
{$ENDIF}
end; 
 
The initialization get called:
 
initialization
 CefRemoteDebuggingPort := 9000;
 CefRenderProcessHandler := TCustomRenderProcessHandler.Create;
 CefBrowserProcessHandler := TCustomBrowserProcessHandler.Create;
end.
 
This is just the guiclient demo I have been playing with.
 
Not sure what I am missing.
 
M
 
 
 
 
Michael Brooks 
12/11/18
Hello Mark:
 
What I would like to be able to do is call a Delphi function or procedure passing a string parameter.
 
 
I don't believe you can call a Delphi method directly from TChromium, instead you'll need to do the following:
  1. Add an OnConsoleMessage event to your TChromium component.
  2. Add a "console.log('bla bla bla')" method to your HTML's javascript where "bla bla bla" is the text you want your OnConsoleMessage event to receive through its "Message" parameter.
It's a good idea to prefix your "bla bla bla" with a string that tells you and your Delphi application what you're intending to do.   For example, "bla bla bla" could be "log_click:http://mysite.com" which your OnConsoleMessage event would parse to know that you want to call your Delphi "LogClick" method with "http://mysite.com" as a parameter value.
 
Hope that helps.
 
Michael
   
 
 
 
 
Mark Di Val 
12/11/20
Hi Michael,
 
This does exactly what I need - thank you.
 
Not having had much to do with javascript or DCEF I had no idea about the console or the .log function. Interestingly, having an OnConsoleMessage handler gave me a warning about including multiple references to Google Maps in my html - so that was also useful.
 
I will also take your lead and have that javascript format the polygon data so that the handler can filter that and give the user a "save polygon" dialog.
 
I had been attempting to get a number of the COM/Extension type callback things to work along the lines of various posts on this subject but had had no luck. One of the lines that I tried used objects that didn't exist in the current version of ceflib.pas (perhaps TCefStyleHandlerOwn ? IIRC).
 
I compared files that Tortoise brought down from the trunk with files that you see when browsing the turnk and I note that they are different. Take ceflib.pas for example: I have 14049 lines whereas the browsed trunk had 11000 odd lines when I browsed on the weekend and as I say there where classes in the shorter (and I assume older version) that where not in my SVN copy. I note today (20/11/2012) that "browsing" the source (http://code.google.com/p/dcef3/source/browse/trunk/src/ceflib.pas) this file now has 14143 lines - i.e. changed since Saturday. Is it still then release 23?
 
I guess that all means that the trunk is subject to change without notice - a work in progress.
 
For the more exotic methods of passing data back to Delphi from javascript it would be nice if there was a working VCL example (demo) that uses the current version of the libraries. Lots of the little snippets that people have posted don't quite close the loop.
 
Anyway, thanks again for your help.
 
Cheers,
 
Mark
- 显示引用文字 -
 
 
 
 
Balázs Varga 
12/11/20
Hi,
 
I would be suprised if you would not be able to call a delphi function from javascript with dcef3. In dcef1 it was "simple" with the help of Extensions, see the dcef1 cefclient demo
 
 
just navigate to client://test to see how it did work, if I'm remember correctly.
 
I haven't had time to play with the new dcef3, so don't know whether is it working or not, but I would be surprised if this feature would be missing from dcef3 (or at least I would be very very sad).
 
Balazs 
- 显示引用文字 -
 
 
 
 
此帖已被删除。
Rüdiger Hahn 
12/11/20
Hi,
 
I succeeded doing it as you started. Just create a simple class and register it with "TCefRTTIExtension.Register".
 
I could even use properties with all their benefits like in the following example
 
...
 
type
  TMyClass = class(TObject)
  private
    FValue: string;
  protected
    procedure SetValue(Value: string);
    function GetValue: string;
  public
    property Value: string read GetValue write SetValue;
  end;
 
implementation
 
procedure TMyClass.SetValue(Value: string)
begin
  if (Value <> FValue) then begin
    // set the Value and do anything you want.
    FValue := Value;
    ShowMessage('JavaScript tells us the following: ' + FValue); 
    FValue := FValue + ' This is a modification from Delphi!';
  end;
end;
 
function TMyclass.GetValue: string;
begin
  Result := 'This is the result from the getter: ' + FValue;
end; 
 
 
 
Register class with something like TCefRTTIExtension.Register('myclass', TMyClass);
 
That should it be from Delphi side.
 
In javascript you now just can do things like this:
 
myclass.Value = 'Hello World!';
alert(myclass.Value);
 
There should be two Popups: first a message dialog from Delphi with the text "JavaScript tells us the following: Hello World!" The second will be an alert window from JavaScript with the message "This is the result from the getter: Hello World! This is a modification from Delphi".
 
BTW: I had problems transferring Boolean values from Javascript to Delphi. Nothing happened. Eventually I found out that I had to convert the Boolean values to integers to make them work.
 
At the end I am very happy with the work of Henri Gourvest.
 
Ruediger
 
 
- 显示引用文字 -
 
 
 
 
Henri Gourvest 
12/11/21

BTW: I had problems transferring Boolean values from Javascript to Delphi. Nothing happened. Eventually I found out that I had to convert the Boolean values to integers to make them work.
 
 
I just fixed this bug
 
 
At the end I am very happy with the work of Henri Gourvest.
 
Thank you :)
 
-- 
Henri Gourvest
 
 
 
 
Rüdiger Hahn 
12/11/21
Wow, that was fast.

Thank you so much.

Ruediger

- 显示引用文字 -
附件 (1)
smime.p7s
2 KB   查看   下载
 
 
 
 
Pierre Fontaine 
13/1/18
I have found my error.
It's OK
I attach my unit and a simple html file
Regards,
Pierre

On Thursday, January 17, 2013 4:09:25 PM UTC+1, pierre....@libertysurf.fr wrote:
Hello,
I have the same problem.
Where call  "TCefRTTIExtension.Register "
I can't execute the Javascript!
Thanks,
Pierre

On Wednesday, December 19, 2012 11:00:01 PM UTC+1, Jeremy Coulter wrote:
Hi. well, I must be missing something as I cant get it to work :-(
I am using Delphi XE2, and I followed what you did below and I got an "Undefined" error when the Javascript is run.
 
My problem may be easy as where I am calling "TCefRTTIExtension.Register('myclass', TMyClass);". so I add this to the Implementation section? or the formcreate...or somewhere else....just to let you know I have tried both and with no success.
My JS is as follows:
<script language="JavaScript">
myclass.Value = 'Hello World!';
alert(myclass.Value);
</script>
and I am pretty sure thats ok.
and my Delphi is as per the example below.
Can anyone shed some light? I hope I have provided enough info.
 
Jeremy
- 显示引用文字 -
- 显示引用文字 -
BTW: I had problems transferring Boolean values from Javascript to Delphi. Nothing happened. Eventually I found out that I had to convert the Boolean values to integers to make them work.
 
At the end I am very happy with the work of Henri Gourvest.
 
Ruediger
 
 

Am Dienstag, 13. November 2012 12:44:19 UTC+1 schrieb Mark Di Val:
BTW I notice that this code never gets called - seems fairly critical!
 
procedure TCustomRenderProcessHandler.OnWebKitInitialized;
begin
{$IFDEF DELPHI14_UP}
  TCefRTTIExtension.Register('app', TTestExtension);
{$ENDIF}
end; 
 
The initialization get called:
 
initialization
 CefRemoteDebuggingPort := 9000;
 CefRenderProcessHandler := TCustomRenderProcessHandler.Create;
 CefBrowserProcessHandler := TCustomBrowserProcessHandler.Create;
end.
 
This is just the guiclient demo I have been playing with.
 
Not sure what I am missing.
 
M
附件 (2)
Unit5.pas
1 KB   查看   下载
MonJs.html
597 B   查看   下载
 
 
 
 
Long Mu 
13/4/25
How to work in Delphi7 ???
- 显示引用文字 -
 
 
 
 
Anthony 
13/5/20
其他收件人: ruedige...@googlemail.com
but any ide why i got AV when i change ShowMessage('JavaScript tells us the following: ' + FValue); 
with other command

example::
form1.button1.click;
or
call other function from here?

any thing other showmessage will got AV error

thanks
 
 
 
 
Moharram Bagheri 
15/7/2
Hi

i use Register function of TCefRTTIExtension Class to register an appName, to call my delphi app from JS running in the chromium.

the code is well and i have no problem,

but after calling the delphi function more and more the VM Size of application grows up and the memory consumption increases.

is there a bug with CEF, or i am mistaking in my steps to setup the procedure?

Thanks