Hi Dennis
Hi. If you looked at the definition of TStringItem, you will see that FString is of type string.
Yes, but I want to store a pointer to the memory location of the string. In fact, I'm storing the locations of all strings added to the stringlist. I don't want a copy of the strings as that would double memory requirements.
BTW, I still don't understand why you can't simply do stringlist.Strings[index] to get at the string.
The index will change as items are added because it's a sorted stringlist. I need access to the strings via other classes. But I also need a fast Find operation which the Stringlist provides. I hope that makes sense.
I still don't understand why I can't simply dereference the PString using a ^, which should convert it to a string.
Cheers, Ross.
Hi Ross,
You've been having fun with this over the last few days. I think you may have been mixing up 2 different things.
@ and ^ are complimentary operators, @ returns an address and ^ returns what is at an address.
PString and String are complimentary too but using them casts one type to another which the complier would otherwise recognise as incompatible
Given
a: pointer; p: PString; s, t: String;
a and p are both pointers but you have told the compiler a bit more about what p is supposed to be pointing to.
This works OK p := @s; t := p^;
As does this a := @s; t := a^;
This also works as alternative p := PString(s); t := String(p);
But note that if you do p := PString(s); a := @s; then you will find that p <> a
I guess you know that the address of the string s is the start of the characters in the string and that the other information such as it's length and reference count etc are held at negative addresses relative to the start of the characters. It's been done like that so that strings can be passed to Windows routines which expect C style null terminated strings.
If you are holding addresses of strings anywhere then you're on your own. The system will not inform you if it decides to shift them about as a result of any string operations you may carry out and all the reference counting is out of the window too.
I'm sure you'll be OK if you just tread carefully!
Kit Jackson _______________________________________________ Delphi mailing list [EMAIL PROTECTED] http://ns3.123.co.nz/mailman/listinfo/delphi
