castle-engine
castle-engine copied to clipboard
TCastleDownload remains on dsDownloading forever (using TCastleControlBase and Application.ProcessMessages) because LCL doesn't fire ApplicationProperties._Update
I've replicated examples\network\castle_download as a Lazarus app with a TCastleControlBase
TCastleDownload.Status becomes dsDownloading, the download starts, the file is accessed on the server but the Status stays at dsDownloading permanently.
Adding a WaitForFinish makes it at least work but this will then stop the asynchronous reporting functionality.
Attached is a test Lazarus app that's basically a rip-off of castle_download (The abort button is essential)
Tested on Win10
The reason is using Application.ProcessMessages
in a loop. In an LCL application without Application.ProcessMessages
(that only reacts to events) it would work OK.
For now, you need to manually call ApplicationProperties._Update
right after calling Application.ProcessMessages
. (use unit CastleApplicationProperties
to have CGE ApplicationProperties
singleton). I'm looking how to make it not necessary -- not yet sure whether LCL gives me this possibility, unfortunately.
Tested that it works OK on Linux,
-
Once I add
ApplicationProperties._Update
call. -
And you need to define
{$define UseCThreads}
in main program file (this is a consequence of FPC and Lazarus on Unix not including TThread support by default) to make it work on Linux. -
Tested downloading with larger file (
http://castle-engine.io/latest.zip
), to make sure DownloadedBytes and TotalBytes also work OK.
It says in the docs that "If your application uses TCastleWindowBase or TCastleControlBase, then this just works." - this is the only reason I actually put a TCastleControlBase in the project and change the caption a lot (shows TCastleControlBase.Update is running)
[Thinking out loud time]... You realise that TCastleDownload is something that a lot of non-CGE devs would have use for? Well, once any remaining issues are resolved anyway... It'd be a good way to increase the awareness of CGE, esp if there was Delphi version as well.
It says in the docs that "If your application uses TCastleWindowBase or TCastleControlBase, then this just works."
Which is why it remains an open issue. I'd like to fix it. Likely, it will require an action from Lazarus LCL to enable proper integration with their message loop.
And it indeed "just works" if you don't use Application.ProcessMessages
but rely on events.