如何使用Chromium Embedded(CEF)加载本地html文件?

问题描述 投票:1回答:1

我想加载一个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文章。

delphi chromium-embedded delphi-10-seattle
1个回答
1
投票

这是我在我的代码中这样做的方式:

CBrowser.Load('file:///' + ReplaceStr(fpath, '\', '/'));
© www.soinside.com 2019 - 2024. All rights reserved.