Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

delphi string messages

Posted on 2006-04-07
2
Medium Priority
?
686 Views
Last Modified: 2008-02-01
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 ?

0
Comment
Question by:yarek
2 Comments
 
LVL 11

Expert Comment

by:robert_marquardt
ID: 16399526
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.
0
 
LVL 12

Accepted Solution

by:
Ivanov_G earned 1500 total points
ID: 16402140
How to Send Information (String, Image, Record) Between Two Applications
http://delphi.about.com/od/windowsshellapi/a/wm_copydata.htm
0

Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Have you ever had your Delphi form/application just hanging while waiting for data to load? This is the article to read if you want to learn some things about adding threads for data loading in the background. First, I'll setup a general applica…
Hello everybody This Article will show you how to validate number with TEdit control, What's the TEdit control? TEdit is a standard Windows edit control on a form, it allows to user to write, read and copy/paste single line of text. Usua…
We’ve all felt that sense of false security before—locking down external access to a database or component and feeling like we’ve done all we need to do to secure company data. But that feeling is fleeting. Attacks these days can happen in many w…
Loops Section Overview
Suggested Courses

810 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question