LoadString doesn't work, neither RTTIExtension

47 views
Skip to first unread message

Victor Alberto Gil

unread,
Jan 30, 2015, 6:34:39 PM1/30/15
to wa...@googlegroups.com
Hello, I wrote a simple extension application in order to get some variables from Chromium, it works with DCEF3, but it doesn't work with WACEF.

unit Unit1;

interface

uses
  Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants, System.Classes, Vcl.Graphics,
  Vcl.Controls, Vcl.Forms, Vcl.Dialogs, Vcl.ExtCtrls,
  Vcl.StdCtrls, WACefComponent, wacefowns, Waceflib;

type
  TForm1 = class(TForm)
    Panel1: TPanel;
    Timer1: TTimer;
    Button1: TButton;
    WAChromium1: TWAChromium;
    procedure FormCreate(Sender: TObject);
    procedure Button1Click(Sender: TObject);
    procedure Timer1Timer(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

  TCustomRenderProcessHandler = class(TCefRenderProcessHandlerOwn)
  protected
    procedure OnWebKitInitialized; override;
  end;

  TApp = class
    class procedure getChangingValue(val: variant);
  end;
var
  Form1: TForm1;

implementation

{$R *.dfm}

procedure TCustomRenderProcessHandler.OnWebKitInitialized;
begin
  TCefRTTIExtension.Register('app', TApp);
end;

class procedure TApp.getChangingValue(val: variant);
begin
  Form1.Caption:=VarToStr(val);
end;

procedure TForm1.Button1Click(Sender: TObject);
begin

  if Timer1.Enabled then Button1.Caption := 'OFF'
  else Button1.Caption := 'ON';
  Timer1.Enabled:=not Timer1.Enabled;
  
end;

procedure TForm1.FormCreate(Sender: TObject);
var
  html : string;
begin
  html := '<html><head></head><body><h1>RTTExtension bug</h1<div id="datetime"></div>'+
  '<script type="text/javascript">'+
  'function date_time()'+
  '{'+
        'date = new Date;'+
        'year = date.getFullYear();'+
        'month = date.getMonth();'+
        'months = new Array("January", "February", "March", "April", "May",'+
        '"June", "July", "August", "September", "October", "November", "December");'+
        'd = date.getDate();'+
        'day = date.getDay();'+
        'days = new Array("Sunday", "Monday", "Tuesday", "Wednesday", "Thursday",'+
        '"Friday", "Saturday");'+
        'h = date.getHours();'+
        'if(h<10)'+
        '{'+
                'h = "0"+h;'+
        '}'+
        'm = date.getMinutes();'+
        'if(m<10)'+
        '{'+
                'm = "0"+m;'+
        '}'+
        's = date.getSeconds();'+
        'if(s<10)'+
        '{'+
                's = "0"+s;'+
        '}'+
        'ms = date.getMilliseconds();'+
        'if(ms<10)'+
        '{'+
                'ms = "0"+ms;'+
        '}'+
        'result = ""+days[day]+" "+months[month]+" "+d+" "+year+" "+h+":"+m+":"+s+":"+ms;'+
        'document.getElementById("datetime").innerHTML = result;'+
        'setTimeout(date_time,10);'+
        'return true;'+
  '}'+
  'date_time();</script>'+
  '</body></html>';
  WaChromium1.Browser.MainFrame.LoadString(html, '');
end;

procedure TForm1.Timer1Timer(Sender: TObject);
begin
  WaChromium1.Browser.MainFrame.ExecuteJavaScript(
  'app.getChangingValue(document.getElementById("datetime").innerText)','',0);
end;

initialization
  CefRenderProcessHandler := TCustomRenderProcessHandler.Create;
end.

It is supposed to update the application's caption using the time generated by the javascript. The purpose is to have an extension that will allow me to get dynamic information from webapps.

About the Extension, if I load the simple html from a localhost server, it shows perfectly, but the extension call app.getChangingValue doesn't work.

BTW: How can I enable ShowDevTools?
Reply all
Reply to author
Forward
0 new messages