I now have a rather rare situation. I have an application which directly interacts with Windows' message queue. This application also runs external Lua scripts with LuaJIT. I wanted to have a debugging facility for these scripts, so I've created a plain VCL application, and then converted it into a DLL library. When the first application starts a debugging session with the library, this DLL creates a separated thread, where the whole VCL facility is initialized and run.
procedure TDebuggerThread.Execute;
begin
Application.Initialize;
Application.MainFormOnTaskbar := True;
Application.CreateForm (TMainForm, MainForm);
Application.Run;
end;
Does VCL fully supports being executed this way? To which thread will TThread.Synchronize (Proc: TThreadProc)
send its message?
Inb4 "messages to VCL and to the main application will mess" - they won't because every thread has its own message queue.
Also, you may see the sources here. (Maybe) problematic library is named LuaDebugger
. In place of a proper client (Core
, Engine
, Client
) I'm currently using LuaDefaultHost
, which is a rather simple console application, calling for the debugger and behaving mostly like lua.exe
.
With the console client, debugger works surprisingly smooth - the only problem I've encountered is that if I close the console window while the library is still used, VCL throws "Window handler is no longer valid" (in Russian :/ ). If I let the client to finish interacting with debugger the way it's supposed to, everything goes nice. Probably calling Windows.TerminateThread
during unit finalization should fix that.