delphi string messages

HELLO HERE IS MU code to send STring messages between 2 applications


unit Unit1;
interface

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


type
  TForm1 = class(TForm)
    Label1: TLabel;
    Label2: TLabel;
    Button1: TButton;
    procedure Button1Click(Sender: TObject);
  private
    { Déclarations privées }
  public
    { Déclarations publiques }
    procedure DefaultHandler(var msg); override;

  end;

var
  Form1: TForm1;
var
  WM_OURMESSAGE: DWORD;

implementation

{$R *.dfm}
procedure TForm1.DefaultHandler(var msg);
var
  buffer: PChar;
  atom_recu:Atom;
  TexteRecu:pchar;
begin

  with TMessage(msg) do
  begin
    if (Msg = WM_OURMESSAGE) then
    begin
      // Checking if this message is not from us
      if WParam <> Handle then  begin;

      ************************** THERE IS A BUG HERE ***********************************************************
       ******************************************************************************************************  
       label1.Caption:=(pchar(pointer(lparam)));
       ******************************************************************************************************  

       end;
    end;
end;
inherited DefaultHandler(msg);
end;


procedure TForm1.Button1Click(Sender: TObject);
var buffer: PChar;
atom_Envoye: Atom;
var s:string;

begin
s:='hello world';
s := s + #0;
   SendMessage(HWND_BROADCAST,WM_OURMESSAGE,Handle,longint(@s[1]));
end;

initialization
  WM_OURMESSAGE := RegisterWindowMessage('Our broadcast message');

end.



Messages are processed but I have  a ERROR (pointer error I suppose) with
label1.Caption:=(pchar(pointer(lparam)));

after I have sent a message with
SendMessage(HWND_BROADCAST,WM_OURMESSAGE,Handle,longint(@s[1]));


how to correct it ?

yarekAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

robert_marquardtCommented:
You get the message from another application?
Then any pointer from the other application is invalid in your application because each application uses its own virtual address space.
You either have to use WM_COPYDATA where the OS transfers a data structure between the applications or use a Memory Mapped File as a sharing mechanism.
See Win32 functinos CreateFileMapping and MapViewOfFile.
Ivanov_GCommented:
How to Send Information (String, Image, Record) Between Two Applications
http://delphi.about.com/od/windowsshellapi/a/wm_copydata.htm

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Delphi

From novice to tech pro — start learning today.