I am trying to bridge two applications (MT4 strategy testers) together through a GUI application I made with Lazarus. I am using TSimpleIPCServer and TSimpleIPCClient.
Tester_1 -------> Central_Application <------- Tester_2
Tester_1 and Tester_2 are using a .dll file that I made which allows communication between them and Central_Application.
cliff's notes of question: What is the best way to freeze Tester_1 until it receives a message from Central_Application?
extended version of question:
When a certain condition occurs Tester_1 must freeze all actions and wait for Central_Application to send it a message before proceeding. Central_Application will get this message from Tester_2 an undefined amount of time after receiving the request from Tester_1.
While waiting for this specific message to arrive from Tester_2, Central_Application must be able to receive/send/process other communications with Tester_2.
From what I understand, I need to use threads to do this...
From the Central_Application I use application.processmessage .
But how about from the .dll files attached to Tester_1 and Tester_2? Do I have to use TThread?
Am I on the right track with this code?:
constructor TYourThread.Create(CreateSuspended: boolean);
begin
FreeOnTerminate := True;
inherited Create(CreateSuspended);
end;
destructor TYourThread.Destroy;
begin
CloseHandle(FEvent);
end;
procedure TYourThread.Execute;
begin
while (not server1.PeekMessage(INFINITE, False)) and (not Terminated) do
begin
Sleep(500);
end;
SetEvent(FEvent);
end;
function GetVar2(): ansistring; stdcall;
var
srvmsg: ansistring;
begin
srvmsg := 'VAR2_TRANSFER_FAIL';
server1 := TSimpleIPCServer.Create(nil);
server1.Global := True;
server1.ServerID := '98765';
server1.Startserver;
YourThread := TYourThread.Create(True);
SendMsg('get2','0');
YourThread.Resume;
if (WaitForSingleObject(YourThread.FEvent, INFINITE) = WAIT_OBJECT_0) then
begin
srvmsg := server1.StringMessage;
end;
YourThread.Terminate;
server1.StopServer;
Result := srvmsg;
end;
I know that various completed systems are already out there for communication between separate MT4 apps, but I want to do it myself(ish) with lazarus.
I'd appreciate any tips or lazarus code that may help me out!