Suggestion for 2 updates
Great work, thanks !
Looking at the reference c header file https://github.com/webview/webview/blob/master/webview.h, and after testing (Windows only but it should be the same on Linux & MacOSX), let me suggest two updates :
-
It's possible to add a useful declaration in
webview.pas:procedure webview_set_html(w: PWebView; const html: PAnsiChar); cdecl; external webview_lib; -
in
lclembedexample, there is an improvement in CreateWebView and DestroyWebView calls, because the c reference header file indicates thatwebview_run()is a message loop running until it's terminated by a call towebview_terminate(). Sowebview_run()is a blocking call. It is required in a pascal command line program but not in a LCL GUI application.
This leads to the following changes in lclembed GUI application :
CreateWebView :
if wvHandle <> nil then
begin
webview_bind(wvHandle, PAnsiChar('HostSayHello'), @SayHello, nil);
webview_navigate(wvHandle, PAnsiChar('http://localhost:8000/'));
// webview_run(wvHandle); // <-- no need to call this in a GUI application
end
else
// Use GUI dialog, not writeln.
writeln('Failed to create webview object.');
Then to destroy the webview we only need to call webview_destroy() :
procedure TForm1.OnClickExitProgram(Sender: TObject);
begin
isExiting := true;
// if wvHandle <> nil then
// webview_terminate(wvHandle); // <-- not needed in a GUI application
// Sleep(500); <-- not needed too, i suppose (don't know why it's here)
fphttpapp.Application.Terminate;
if wvHandle <> nil then
webview_destroy(wvHandle);
wvHandle := nil;
WebPanel.Hide;
// Halt; <-- not needed, the application will close gracefully because it's not blocked anymore by webview_run()
end;end;
without webview_run() we lost functionality of bind functions, promise will not return result becouse void run() { MSG msg; BOOL res; while ((res = GetMessage(&msg, nullptr, 0, 0)) != -1) { if (msg.hwnd) { TranslateMessage(&msg); DispatchMessage(&msg); continue; } if (msg.message == WM_APP) { auto f = (dispatch_fn_t *)(msg.lParam); (*f)(); delete f; } else if (msg.message == WM_QUIT) { return; } } }
If you need to use bind function there are two ways :
-
call webview_run() in an asynchronous call so that the main GUI thread is not frozen (QueueAsyncCall or PostMessage), and call webview_terminate() in the Form.OnClose() event
-
create a TThread and put every webview_xxx call inside
I've built a TControl descendant which works great in the main GUI thread with every features, I'll publish it soon.
I've built a TControl descendant which works great in the main GUI thread with every features, I'll publish it soon.
thank you, looking forward to it ^_^
1. It's possible to add a useful declaration in `webview.pas` : `procedure webview_set_html(w: PWebView; const html: PAnsiChar); cdecl; external webview_lib; `
I've added this in the WIP branch, which I should be publishing soon.
2. in `lclembed` example, there is an improvement in CreateWebView and DestroyWebView calls, because the c reference header file indicates that `webview_run()` is a message loop running until it's terminated by a call to `webview_terminate()`. So `webview_run()` is a blocking call. It is required in a pascal command line program but not in a LCL GUI application.This leads to the following changes in
lclembedGUI application :
Thanks, I'll test the changes.
I've built a TControl descendant which works great in the main GUI thread with every features, I'll publish it soon.
Looking forward to it.