Hello guys, basically I have two Delphi applications which I want to communicate and work with each other, the only problem is I don't know how. Can anyone help me create a as simple as possible programs so that when I press a button in the first program, it would send a command to the second delphi program and press a button on the second delphi program.

Is this possible? Can you please help me in details, I have spent hours on the internet with no programs working or any luck. Please help me out guys :D.

Thanks you so much for your reply, I have managed to get it working without compiler errors BUT I keep on getting errors with the program itself telling me no reciept is found.

In the first program what should I put in the edit box to make it communicate with the other program? I've tried different names that I saved the application as but it never worked. Any ideas on what window name I should be entering?

Give a look at your code. Without seeing the code is hard to say what the problem.
By the way, if you want to click, you can directly send a message to the button. Likewise, using FindWindow

My source code is pretty much the exact same source code you gave me lol... I will put this code in my main programs later but first I just want to learn and understand how this works before I do that. Click on the below link, it shows you the first application and the second application.

ttp://i51.tinypic.com/123a4ih.png

In the first application where the edit box is, when you type in the Caption for the second application and hit "Button1" it should send the message over right? or so I belive. What actually happens is I get the ShowMessage error as you can see displayed telling me "No Recipient found!" which I think means it does not recognize the second application. Why is this?

Here is the source code for "First Application":

unit oneMain;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, StdCtrls;

type
  TfApp = class(TForm)
    Button1: TButton;
    Edit1: TEdit;
    procedure Button1Click(Sender: TObject);
  private
  public
    { Public declarations }
  end;

var
  fApp: TfApp;

implementation

{$R *.dfm}

procedure TfApp.Button1Click(Sender: TObject);
var
   aCopyData: TCopyDataStruct;
   hTargetWnd: HWND;
begin
   with aCopyData do
   begin
     dwData := 0;
     cbData := StrLen(PChar(Edit1.Text)) + 1;
     lpData := PChar(Edit1.Text)
   end;
   // Search window by the window title 
  // Fenster anhand des Titelzeilentext suchen 
  hTargetWnd := FindWindowEx(0, 0, nil, PChar('WM_COPYDATA-Receiver'));
   if hTargetWnd <> 0 then
     SendMessage(hTargetWnd, WM_COPYDATA, Longint(Handle), Longint(@aCopyData))
   else
     ShowMessage('No Recipient found!');
end;

end.

Here is the source code for "Second Application":

unit twoMain;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, StdCtrls;

type
  TsApp = class(TForm)
    Label1: TLabel;
  private
    procedure WMCopyData(var Msg: TWMCopyData); message WM_COPYDATA;
  public
    { Public declarations }
  end;

var
  sApp: TsApp;

implementation

{$R *.dfm}

procedure TsApp.WMCopyData(var Msg: TWMCopyData);
 var
   sText: array[0..99] of Char;
 begin
   // generate text from parameter 
  // anzuzeigenden Text aus den Parametern generieren 
  StrLCopy(sText, Msg.CopyDataStruct.lpData, Msg.CopyDataStruct.cbData);
   // write received text 
  // Empfangenen Text ausgeben 
  label1.Caption := sText;
 end;

end.

I hope this is a more detailed response :).

Also, can I just explain that these new functions and methods are very new and confusing for me so please be very kind and give me slightly longer detailed replies so I can understand this stuff :D. For example, could you make me two simple applications which in the first application you press a button, when you do this it sends a command to the second application and presses the button on the second application. When this happens the second applications simply shows a message "You have successfully pressed this button from a different application" or something like that, if you can do this then I can examine your code and maybe I will understand how to do this.

I know I'm asking for a bit much but please please, I've been waiting days to find out about this and the wait is killing me as it's all I'm focusing on.

Thanks.

P.S. I'm using the Delphi 7 IDE.

Problem in this line:
hTargetWnd := FindWindowEx(0, 0, nil, PChar('WM_COPYDATA-Receiver'));

You have incorrect settings. We had to read. The third parameter - the window class name to search for, and the fourth - his title. If you specify these two parameters, the search will give 100% result. If you specify only one of them - not the fact that he would find.

I'm a bit at the same time simplify the code and adapt it to Delphi2009 (I write this version). This line calculates the amount of data transmitted. In D2009-line PChar = PWideChar. That's how we calculate the exact size - SizeOf (PChar):

cbData := Length(Edit1.Text) * SizeOf(PChar);

Complete working example, see the attached file.

Thanks it worked.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.