My app will have several tasks for various actions.
All tasks are created in FormCreate and terminated in FormDestroy, they are always running as long as the app is running.
The main thread's only purpose is to handle user I/O and send user inputs to the appropriate task or receive task information to be displayed in the main form.
There will be data that has to be transferred between tasks.
Example:
I will have task A doing data processing.
It will send some of it's results to the main thread for displaying.
It will also have to send some (other) data to task B, which will transfer the data to another PC.
Task C will receive some data from a hardware device and has to send this data to task A for processing.
etc...
As I understand so far, sending messages with OmniThreadLibrary is always between the task and the thread that created the task (Main thread and task A, or Main thread and task B).
How can I send messages directly between any two tasks?
Or is there any problem with my approach so far and it should be done completely different?
Possible. You have to create a communication channel in the owner and pass it to both tasks. In the task you then call Task.RegisterComm to register this communication channel. From that point onwards, all messages received on this channel will be dispatched using the standard OmniThreadLibrary mechanisms (i.e. exactly as if they would be sent from the owner).
See demo 08_RegisterComm for an example.
procedure TfrmTestRegisterComm.FormCreate(Sender: TObject);
begin
FCommChannel := CreateTwoWayChannel(1024);
FClient1 := CreateTask(TCommTester.Create(FCommChannel.Endpoint1))
.Run;
FClient2 := CreateTask(TCommTester.Create(FCommChannel.Endpoint2))
.Run;
end;
function TCommTester.Initialize: boolean;
begin
Task.RegisterComm(ctComm);
Result := true;
end;