I have the following code, which I used back in a TWebBrowser project to handle a quick few calls to a webpage. Now, while this is probably not the "best" way to handle this, the crmBrowser is logged in and should in theory be able to do 5 calls in quick succession. TChromium is, faster, multithreaded and does not appear to be inclined to wait however.
This is the snipped in question that's bothering me currently:
for I := 0 to Urls.Count-1 do begin
FrmDBrowser.crmBrowser.Load('http://www.dragontavern.com' + Urls[I]);
if I < Urls.Count-1 then begin
Application.ProcessMessages;
Sleep(FrmDBrowser.Config.CubeDelay);
end;
end;
It is started through a callback:
CefStringVisitor := TCefFastStringVisitor.Create(InventoryListCallback);
crmBrowser.Browser.MainFrame.GetSource(CefStringVisitor);
Basically, I have a TStringlist with sub-links that need to be called. But, when I run the above code with for example 3 links in there,. only the last call gets handled. And the sleep is pretty much ignored as well.
This was the code for TWebBrowser:
for I := 0 to Urls.Count-1 do begin
webbrowser1.Navigate('http://www.dragontavern.com' + Urls[I]);
if I < Urls.Count-1 then begin
Application.ProcessMessages;
Sleep(FConfig.CubeDelay);
end;
end;
As you can see, pretty similar. Except that it was started by the user from the main thread. I guess this will be an easy question to answer but, sleep in a callback proc will not affect the main thread, hence to get this working I'm going to need to synchronize or postmessage to the main form? Or would there be a slightly easier way to have the TChromium run multiple urls one after the other?
If you'd like to look at the full source and run the project, feel free to nose around at: https://bitbucket.org/tstki/dragontavern-logger
(I'm aware that Application.ProcessMessages is an ugly thing)