[DUG] Reference counting
Rohit Gupta
rohit at cfl.co.nz
Thu Nov 24 17:43:51 NZDT 2005
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" <paul_lowman at xtra.co.nz>
To: "Delphi List" <delphi at delphi.org.nz>
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 <delphi at ns3.123.co.nz>
<mailto:delphi-request at ns3.123.co.nz?subject=unsubscribe>
<mailto:delphi-request at ns3.123.co.nz?subject=subscribe>
[ 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
Delphi at ns3.123.co.nz
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 rohit at cfl.co.nz or r.gupta at xtra.co.nz
======================================================================
More information about the Delphi
mailing list