unit SenderMain;

interface

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

type
  TfMain = class(TForm)
    btnSend: TButton;
    GroupBox1: TGroupBox;
    leText: TLabeledEdit;
    leSquare: TLabeledEdit;
    procedure btnSendClick(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

  TExchange = record
    DT : TDateTime;
    Name : string[100];
    Square : real;
  end;

var
  fMain: TfMain;

implementation

{$R *.dfm}

procedure TfMain.btnSendClick(Sender: TObject);
var
  aCopyData  : TCopyDataStruct;
  hTargetWnd : HWND;
  Ex : TExchange;
begin
  with Ex do begin
    DT := Now;
    Name := leText.Text;
    try Square := StrToFloat(leSquare.Text);
    except
      MessageDlg('Недобре введено число!', mtWarning, [mbCancel], 0);
      Exit;
    end;
  end;
  with aCopyData do begin
    dwData := 0;
    cbData := SizeOf(Ex);
    lpData := @Ex;
  end;
  // Пошук вікна-отримувача за його назвою
  hTargetWnd := FindWindow(nil, PChar('Отримувач'));
  if hTargetWnd <> 0 then
    SendMessage(hTargetWnd, WM_COPYDATA, DWORD(Handle), DWORD(@aCopyData))
  else ShowMessage('Не знайдено отримувача!');
end;

end.
