Как передать строку другому приложению

Материал из DRKB

Как передать строку другому приложению[править | править код]

получатель:


type
  TFormReceive = class(TForm)
  private
    procedure ReceiveMessage(var Msg: TMessage); message WM_COPYDATA;
  end;

implementation

procedure TFormReceive.ReceiveMessage;
var
  pcd: PCopyDataStruct;
begin
  pcd := PCopyDataStruct(Msg.LParam);
  Caption := PChar(pcd.lpData);
end;


отправитель:

procedure TFormXXX.Button1Click(Sender: TObject);
var
  cd: TCopyDataStruct;
begin
  cd.cbData := Length(Edit1.Text) + 1;
  cd.lpData := PChar(Edit1.Text);
  SendMessage(FindWindow('TFormReceive', nil), WM_COPYDATA, 0, LParam(@cd));
end;


Source: http://delphiworld.narod.ru/
ID: 02142