Solved

String in Windows message

Posted on 2010-11-17
6
535 Views
Last Modified: 2012-06-21
Hello experts

I know how to send message to the system.
It looks like:

PostMessage(MyParams.HandleToForm, WM_THREAD_COMPLETE, LInteger0,
LInteger1);

Where I have handle to the form with procedure, name of the procedure and two integer parameters.

Question:

How can I pass parameter of String type?

Thank you

panJames
0
Comment
Question by:panJames
  • 4
6 Comments
 
LVL 19

Expert Comment

by:Thommy
ID: 34154219
0
 
LVL 24

Expert Comment

by:jimyX
ID: 34154231
You can do something like this:


Str : String;

PostMessage(MyParams.HandleToForm, WM_THREAD_COMPLETE, @Str, LInteger1);
0
 
LVL 24

Expert Comment

by:jimyX
ID: 34154285
That one will not work. But this will:

  Str:string;
  A : Integer;

  Str := 'test';
  A := GlobalAddAtom(Pchar(Str));
  PostMessage(MyParams.HandleToForm, WM_THREAD_COMPLETE, iAtom, LInteger1);
0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 24

Expert Comment

by:jimyX
ID: 34154403
 Str:string;
  A : Integer;

  Str := 'test';
  A := GlobalAddAtom(Pchar(Str));
  PostMessage(MyParams.HandleToForm, WM_THREAD_COMPLETE, A, length(Str));
0
 
LVL 24

Accepted Solution

by:
jimyX earned 500 total points
ID: 34154615
This also is valid:

Str : String;

PostMessage(MyParams.HandleToForm, WM_THREAD_COMPLETE, integer(Str), length(Str));
0
 
LVL 26

Expert Comment

by:Russell Libby
ID: 34155054
Just keep the following rules in mind when passing strings (or any pointers, eg objects, etc):

- If you PostMessage with a string, you have to ensure the pointer (string) does not go out of scope before the window processes the message. Not a recommended way of sending strings.
- If you are SendMessage(..) ing strings/pointers, you can do so without issues as long as the window handling the message exists within the process.
- If you are SendMessage(..) ing strings/pointers to a window that exists in another process, then you will need to use some form of IPC (WM_COPYDATA, atoms, etc) as the pointer you are passing needs to be mapped into the process space of the window handling the message.

Russell

0

Featured Post

Free Tool: Postgres Monitoring System

A PHP and Perl based system to collect and display usage statistics from PostgreSQL databases.

One of a set of tools we are providing to everyone 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

Suggested Solutions

Title # Comments Views Activity
Working this component WebCopy with proxy, help 3 102
Delphi Form ownership 4 127
oracle global variables 4 80
Get weeknumber and year from date 4 31
This article explains how to create forms/units independent of other forms/units object names in a delphi project. Have you ever created a form for user input in a Delphi project and then had the need to have that same form in a other Delphi proj…
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…
A short tutorial showing how to set up an email signature in Outlook on the Web (previously known as OWA). For free email signatures designs, visit https://www.mail-signatures.com/articles/signature-templates/?sts=6651 If you want to manage em…
Finding and deleting duplicate (picture) files can be a time consuming task. My wife and I, our three kids and their families all share one dilemma: Managing our pictures. Between desktops, laptops, phones, tablets, and cameras; over the last decade…

726 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