【发布时间】:2018-09-09 01:25:15
【问题描述】:
我想将一个 html 文件加载到 Chromium (CEF4Delphi) 但什么都没有显示,只有一个白页。
是否可以使用以下方法加载本地 html 文件?
Here是html文件。
还有其他问题,即每次执行 Chromium 时,也会执行我的应用程序的其他实例。如何解决?
使用的代码:
var
Form1: TForm1;
FStarted: Boolean;
implementation
{$R *.dfm}
function CEFApplication: TCefApplication;
var
sPath: String;
begin
sPath := ExtractFilePath(ParamStr(0));
if not assigned(GlobalCEFApp) then
begin
GlobalCEFApp := TCefApplication.Create;
GlobalCEFApp.FlashEnabled := False;
GlobalCEFApp.FastUnload := True;
GlobalCEFApp.FrameworkDirPath := sPath + 'cef';
GlobalCEFApp.ResourcesDirPath := sPath + 'cef';
GlobalCEFApp.LocalesDirPath := sPath + 'cef\locales';
GlobalCEFApp.Cache := sPath + 'cef\cache';
GlobalCEFApp.Cookies := sPath + 'cef\cookies';
GlobalCEFApp.UserDataPath := sPath + 'cef\User Data';
GlobalCEFApp.EnableGPU := False;
end;
if not FStarted then
FStarted := GlobalCEFApp.StartMainProcess;
result := GlobalCEFApp;
end;
initialization
CEFApplication;
end.
Form2:
procedure TForm2.FormShow(Sender: TObject);
begin
while not(Chromium1.CreateBrowser(CEFWindowParent1, '')) and
(Chromium1.Initialized) do
begin
Sleep(100);
Application.processMessages;
end;
Chromium1.LoadURL(ExtractFilePath(ExtractFilePath(Application.ExeName)) + 'gmaps.html');
end;
版本:
相对于我对正在执行的应用程序的多个实例的怀疑,这是正常且正确的,基于this 文章。
【问题讨论】:
-
使用 Chrome。打开同一个本地 HTML 文件,然后查看地址栏。那里的文件名是什么样的?和你的格式相符吗?
-
@KenWhite,完全正确(文件名和路径)。
标签: delphi chromium-embedded delphi-10-seattle cef4delphi