----- Original Message -----
Sent: Thursday, November 24, 2005 10:29
PM
Subject: RE: Re: [DUG] Reference
counting
[Reply]
Hi
all,
To
"send a string" using windows messaging, use Global Atoms, and send the
reference to the Atom in the Windows Message.
Look
at:
http://www.delphipages.com/threads/thread.cfm?ID=24029&G=24027
cheers
Gary
At 19:43 on
24/11/2005 you wrote
>To : [EMAIL PROTECTED],[email protected]
>CC :
>From: Kyley Harris, [EMAIL PROTECTED]
>Content Type: text/plain
>Attached:
>
>There are two basic ways to send a string, seeing
as we are talking
>postmessage,
>here is the fugly one.
>
>p:phar;
>
>GetMem(p,length(data));
>move(data[1],p^,length(data));
>postmessage(bla bla , integer(p));
>
>remember to free mem on the other
side.
>
>Better and nicer way
>
>TString = class(TObject)
>
property data:string;
>end;
>
>Create and send a reference to this, and free it
when you are finished.
>remember none of these options is safe outside of
your own application.
>
>
>
>On Thu, 24 Nov 2005 17:43:51 +1300, Rohit Gupta
<[EMAIL PROTECTED]> wrote:
>
>> I cant see how it can be safe. I was stumped
as well when I wanted
>> to send a string in a message. I had to
abandon my ideas.... :-( Let
>> me know if you have any joy.
>>
>> From: "Paul Lowman"
<[EMAIL PROTECTED]>
>> To: "Delphi List"
<[email protected]>
>> Date sent: Thu, 24 Nov
2005 16:22:04 +1300
>> Copies to:
>> Subject: [DUG]
Reference counting
>> Send reply to: NZ
Borland Developers Group - Delphi List
>> <[email protected]>
>>
<mailto:[EMAIL PROTECTED]>
>>
<mailto:[EMAIL PROTECTED]>
>>
>> [ Double-click this line for list subscription
options ]
>>
>> Heres one for the gurus -
>>
>> Assume a long string variable is declared
locally to a method and is
>> assigned a string and the string variable is
then typecast as an integer
>> and
>> used in - say - a windows message by assigning
it to the message lparam.
>>
>> The question is when the message is received
by another form / thread is
>> it
>> valid to then typecast the lparam back to a
string and use it ?
>>
>> I have tried many variations of this scenario
and it seems to work OK
>> but am
>> uneasy about whether or not this is safe. I
assume it isn't as the local
>> string variable (which points to the actual
string) is on the stack and
>> is
>> not maintained after the method is exited but
what I really am concerned
>> about is the reference count for the string -
has it been increased by
>> typecasting it to an integer / pointer
whatever ...
>>
>> I have used some of Marco Cantu's code to try
and examine the strings
>> reference count and it always appears to be -1
if the string is a local
>> variable although it works correctly for field
or global.
>>
>> All very confusing :-)
>>
>> I would like to know how the code knows when
to inc / dec / dispose the
>> stirng / array reference count.
>>
>> Cheers
>>
>> Paul Lowman
>>
>>
_______________________________________________
>> Delphi mailing list
>> [email protected]
>>
http://ns3.123.co.nz/mailman/listinfo/delphi
>> Regards
>>
>> Rohit
>>
>>
======================================================================
>> CFL - Computer Fanatics Ltd. 21 Barry's Point
Road, AKL, New Zealand
>> PH (649) 489-2280
>> FX (649) 489-2290
>> email [EMAIL PROTECTED] or
[EMAIL PROTECTED]
>>
======================================================================
>>
>>
>>
_______________________________________________
>> Delphi mailing list
>> [email protected]
>>
http://ns3.123.co.nz/mailman/listinfo/delphi
>
>
>
>--
>Kyley Harris
>+64-21-671821
>_______________________________________________
>Delphi mailing list
>[email protected]
>http://ns3.123.co.nz/mailman/listinfo/delphi
>
Ref#: 41006
_______________________________________________
Delphi mailing
list
[email protected]
http://ns3.123.co.nz/mailman/listinfo/delphi