Code: Select all
begin
CreateGlobalCEFApp;
if GlobalCEFApp.StartMainProcess then
begin
Application.Initialize;
Application.MainFormOnTaskbar := True;
Application.Title := 'AppName';
Application.CreateForm(TMainView, MainView);
Application.Run;
end;
DestroyGlobalCEFApp;
end.
Code: Select all
procedure CreateGlobalCEFApp;
var
RegIniFile: TRegIniFile;
DoClearCache: Boolean;
begin
RegIniFile := TRegIniFile.Create('SOFTWARE\AppName');
try
DoClearCache := RegIniFile.ReadBool('', 'ClearCache', False);
finally
RegIniFile.Free;
end;
GlobalCEFApp := TCefApplication.Create;
with GlobalCEFApp do
begin
CheckCEFFiles := False;
OnWebKitInitialized := GlobalCEFApp_OnWebKitInitialized;
Cache := CefCacheDir;
DeleteCache := DoClearCache;
DeleteCookies := False;
EnableHighDPISupport := True;
end;
end.
I had this code in program for quite a while until one day a user said, by the way I keep getting this error. Thousands of users never saw it or it happened so rarely they didn't bother to report it. But one user got it every time.
I had forgotten the way CEF initialization works and that this code gets executed multiple times near simultaneously. And, I had overlooked the fact that TRegIniFile.Create will create a key if one does not already exist, which is the case on the very first run of my app. Be careful what you put in your TCefApplication initialization code.
I decided to pass this along so you can avoid my mistake.
R Greg Dawson