Message sending string

Source: Internet
Author: User

In fact, no matter what method, the root cause is to pass the object pointer to achieve the effect.

Method 1:

Procedure sendstring (strmsg: string );
VaR
Data: tagcopydatastruct;
Pbuf: pchar;
Begin
Getmem (pbuf, length (strmsg) + 1 );

Try
Zeromemory (pbuf, length (strmsg) + 1 );
Strpcopy (pbuf, strmsg );

Data. cbdata: = length (strmsg );
Data. dwdata: = length (strmsg );
Data. lpdata: = pbuf;

Sendmessage (htargetwin, wm_copydata, INTEGER (self. Handle), INTEGER (@ data ));
Finally
Freemem (pbuf );
End;
End;

Procedure wmcopydata (var msg: tmessage); message wm_copydata;

Procedure tform1.wmcopydata (var msg: tmessage );
VaR
Data: ^ tagcopydatastruct;
Strmsg: string;
Begin
Data: = pointer (msg. lparam );

Strmsg: = strpas (data. lpdata );

Showmessage (strmsg );
End;

 

Method 2:

Tmyrecord = record S: string; end;

 

TT: tmyrecord;

 

VaR TT: tmyrecord; begin TT. S: = 's2343243'; postmessage (handle, wm_my, INTEGER (TT), 5); end;
To send a message, because the parameter can only be an integer, you can send only four bytes in this way, so you need to change it to a sending pointer, for example:
VaR TT: tmyrecord; begin TT. S: = 's2343243'; postmessage (handle, wm_my, INTEGER (@ TT), 5); end;
Of course, the original method cannot be used for receiving: My: = tmyrecord (msg. wparam); in this way, the tmyrecord should be declared as a pointer:

Type pmyrecord = ^ tmyrecord; var my: pmyrecord; my: = pmyrecord (msg. wparam );

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.