我想加载一个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.
窗体2:
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文章。
这是我在我的代码中这样做的方式:
CBrowser.Load('file:///' + ReplaceStr(fpath, '\', '/'));