[CLOSED] WebView4Delphi question lazarus / 38-Networking and Web Programming ---------------------------------------------------------------------- egsuh · 2025-10-31 11:18 Hello, I'd like to make a form simply shows the HTML page made from my program using WebView4Delphi. The form is created on fly as follows. Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i procedure TForm1.Button2Click(Sender: TObject);var   ts: string;begin   ts := aqfb5.printQnnr('100000042', -100);    with TfrBrowser.Create(nil, ts) do  begin        Show;        wvbrowser1.navigatetostring(UTF8Decode(ts));  // but this does not work.    end;end;         The content of ts is displayed well on normal webbrowsers. What I want to do is to show this content in a pop-up window, e.g. Tfrbrowser created.  But in the above example, I cannot execute wvbrowser1.navigatetostring(UTF8Decode(ts)); . I do not know why.  Possibly becasue of asynchronous process, etc. Content of fbrowser.pas is as following.  Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i unit fbrowser; {$mode delphi} interface uses   Classes, SysUtils, Forms, Controls, Graphics, Dialogs,   uWVBrowser, uWVWindowParent, uWVLoader, uWVBrowserBase, uWVTypes, uWVEvents,   Messages; type    { TfrBrowser }    TfrBrowser = class(TForm)      WVBrowser1: TWVBrowser;      WVWindowParent1: TWVWindowParent;      procedure FormClose(Sender: TObject; var CloseAction: TCloseAction);      procedure FormResize(Sender: TObject);      procedure FormShow(Sender: TObject);      procedure WVBrowser1AfterCreated(Sender: TObject);   private      FTextContent: string;      procedure setBrowserContent(AValue: string);      procedure Initialize;    public      property HTMLText : string write setBrowserContent;     constructor Create(AnOwner:TComponent; TextContent: string);    protected      procedure WMMove(var aMessage: TWMMove);  message WM_MOVE;      procedure WMMoving(var aMessage: TMessage); message WM_MOVING;    end; var   frBrowser: TfrBrowser; implementation {$R *.lfm} procedure TfrBrowser.WVBrowser1AfterCreated(Sender: TObject);begin    WVWindowParent1.UpdateSize;    Caption := 'View responses';end; procedure TfrBrowser.setBrowserContent(AValue: string);begin   WVBrowser1.NavigateToString(UTF8Decode(AValue));end; procedure TfrBrowser.Initialize;begin  if GlobalWebView2Loader.InitializationError then    showmessage(UTF8Encode(GlobalWebView2Loader.ErrorMessage))   else    if GlobalWebView2Loader.Initialized then begin       WVBrowser1.CreateBrowser(WVWindowParent1.Handle);    end    else begin      showmessage('initialization failed');      exit;    end;end; constructor TfrBrowser.Create(AnOwner: TComponent; TextContent: string);begin   inherited Create(AnOwner);    FTextContent := TextContent;end; procedure TfrBrowser.FormShow(Sender: TObject);begin  if GlobalWebView2Loader.InitializationError then    showmessage(UTF8Encode(GlobalWebView2Loader.ErrorMessage))   else    if GlobalWebView2Loader.Initialized then begin      WVBrowser1.CreateBrowser(WVWindowParent1.Handle);    end    else begin      showmessage('initialization failed');      exit;    end;end; procedure TfrBrowser.FormResize(Sender: TObject);begin    WVBrowser1.NavigateToString(fTextContent);end; procedure TfrBrowser.FormClose(Sender: TObject; var CloseAction: TCloseAction);begin   CloseAction := caFree;end; procedure TfrBrowser.WMMove(var aMessage : TWMMove);begin  inherited;   if (WVBrowser1 <> nil) then    WVBrowser1.NotifyParentWindowPositionChanged;end; procedure TfrBrowser.WMMoving(var aMessage : TMessage);begin  inherited;   if (WVBrowser1 <> nil) then    WVBrowser1.NotifyParentWindowPositionChanged;end;  initialization   GlobalWebView2Loader                := TWVLoader.Create(nil);   GlobalWebView2Loader.UserDataFolder := UTF8Decode(ExtractFileDir(Application.ExeName) + '\CustomCache');   GlobalWebView2Loader.StartWebView2; end.                         Problems are, 1)  WVBrowser executes well like TWVBrowser.Navigate or TWVBrowser.NavigateToString well, ONLY WHEN its defaultURL has been assigned. If it was left blank, I cannot open any page programmatically. 2) If the contents of FormShow is moved to FormCreate, they are not executed correctly. I can put them within OnformActivate. 3) When this Window is opened, it displays the content of WVBrowser.defaultURL.  I assigned FormResize event, and when I resize the Window, the content is replaced with ts. However, I cannot call this PROGRAMMATICALLY. Waiting for advices. ---------------------------------------------------------------------- egsuh · 2025-11-02 07:30 I do not fully understand the mechanism but I found a simplesolution. The content should be defined before the creation of WVBrowser. Windows Message must be playing some role, which I do not understand. Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i type    { TfrBrowser }    TfrBrowser = class(TForm)      WVBrowser1: TWVBrowser;      WVWindowParent1: TWVWindowParent;      procedure Button1Click(Sender: TObject);      procedure FormActivate(Sender: TObject);      procedure FormClose(Sender: TObject; var CloseAction: TCloseAction);      procedure WVBrowser1AfterCreated(Sender: TObject);   private      FTextContent: string;    public      property HTMLText : string write FTextContent;      procedure Initialize;    protected      procedure WMMove(var aMessage: TWMMove);  message WM_MOVE;      procedure WMMoving(var aMessage: TMessage); message WM_MOVING;   end; var   frBrowser: TfrBrowser; implementation {$R *.lfm} procedure TfrBrowser.FormClose(Sender: TObject; var CloseAction: TCloseAction);begin   CloseAction := caFree;end; procedure TfrBrowser.WVBrowser1AfterCreated(Sender: TObject);begin    WVWindowParent1.UpdateSize;    Caption := 'View responses';    WVBrowser1.NavigateToString(Utf8Decode(FTextContent));  // I don't know why but this should be positioned hereend; procedure TfrBrowser.Initialize;begin   if GlobalWebView2Loader.InitializationError then      showmessage(UTF8Encode(GlobalWebView2Loader.ErrorMessage))   else    if GlobalWebView2Loader.Initialized then begin         WVBrowser1.CreateBrowser(WVWindowParent1.Handle);      end      else begin         showmessage('initialization failed');         exit;    end;end; procedure TfrBrowser.Button1Click(Sender: TObject);begin   // WVBrowser1.Navigate('http://www.alphaq.biz');   WVBrowser1.NavigateToString(UTF8Decode('가설라무네'));           // Once initialized, this works well. end; procedure TfrBrowser.FormActivate(Sender: TObject);begin    Initialize;end; procedure TfrBrowser.WMMove(var aMessage : TWMMove);begin  inherited;   if (WVBrowser1 <> nil) then    WVBrowser1.NotifyParentWindowPositionChanged;end; procedure TfrBrowser.WMMoving(var aMessage : TMessage);begin  inherited;   if (WVBrowser1 <> nil) then      WVBrowser1.NotifyParentWindowPositionChanged;end; initialization   GlobalWebView2Loader                := TWVLoader.Create(nil);   GlobalWebView2Loader.UserDataFolder := UTF8Decode(ExtractFileDir(Application.ExeName) + '\CustomCache');   GlobalWebView2Loader.StartWebView2;end.  and calling part: Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i procedure TForm1.Button2Click(Sender: TObject);var   ts: string;begin   ts := 'Good morning';     with TfrBrowser.Create(nil) do begin  // this creates Pop-up form      HTMLText := ts;                            // the HTML content to display is assigned first.      ShowModal;                                // then call FormActivate.   end;end;  It's strange that TWVBrowser is a component dropped from component pallette, but it should be created within the program. ---------------------------------------------------------------------- egsuh · 2025-11-03 02:33 This component displays contents, but takes long sometimes --- several seconds. But still seems this is rather tricky to use --- it does not respond to every event handler. It seems that the operation has something to do with Windows messages. Anyway I prefer this to CEF4 because this needs only one file, WebView2Loader.dll for distribution. ---------------------------------------------------------------------- egsuh · 2025-11-07 05:00 One thing I think I found --- the components needs to be focused to operate correctly. In my case, the TFrame that contains TWVBrowser and TWVWindowParent should be focused before any contents are provided.