morgantop
asked on
WideString usage...
a simple q.
can i use widestring like a regular string type? i mean do i need to alocate/inititialize it or not.
var S: WideString;
S := 'foo';
showmessage(S);
is the above code ok?
or i need to use a Initialize(S) function first (or something else)?
do i need to free S?
can i use widestring like a regular string type? i mean do i need to alocate/inititialize it or not.
var S: WideString;
S := 'foo';
showmessage(S);
is the above code ok?
or i need to use a Initialize(S) function first (or something else)?
do i need to free S?
ASKER
i use D5.
actualy i need to use WideString as a public property in my class.
i guess it would be released when the class is out of scope?
actualy i need to use WideString as a public property in my class.
i guess it would be released when the class is out of scope?
Widestrings are automatically reference counted and release when the ref-count goes to zero. This behavior is identical to that of regular strings (at least in modern versions of Delphi, don't know how far back this goes).
If you are into assember, you can look at the dis-assembly of code that uses string, and you will see the internal equivalent of a try finally block that clear up references to strings.
If you are into assember, you can look at the dis-assembly of code that uses string, and you will see the internal equivalent of a try finally block that clear up references to strings.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
but a wide string is NOT equal to a String
ASKER
gwalkeriq,
from delphi help:
"The WideString type represents a dynamically allocated string of 16-bit Unicode characters. In most respects it is similar to AnsiString, but it is less efficient because it *does not* implement reference-counting and copy-on-write semantics."
anyways, thanks for all suggestions. kinda hard to deside who to give points to...
after testing this myself, the answer "yes" is the right answer to my q. ;)
JodieP, confirmed that "string and widestring are the same" but obviosly they are NOT equal to a Strings as Slick812 stated...
I also dont think it "depends on the version" as JodieP stated.
who do you think i give points to? :-P
if no objections i give points to Slick812.
cheers.
from delphi help:
"The WideString type represents a dynamically allocated string of 16-bit Unicode characters. In most respects it is similar to AnsiString, but it is less efficient because it *does not* implement reference-counting and copy-on-write semantics."
anyways, thanks for all suggestions. kinda hard to deside who to give points to...
after testing this myself, the answer "yes" is the right answer to my q. ;)
JodieP, confirmed that "string and widestring are the same" but obviosly they are NOT equal to a Strings as Slick812 stated...
I also dont think it "depends on the version" as JodieP stated.
who do you think i give points to? :-P
if no objections i give points to Slick812.
cheers.
Well to be fair yes, the appropiate answer is from Slick812 so go ahead
of course I never believed that string and widestring are the same but for the proposes of yr code... it is
Anyway I was away from expert exchange for a while and it's good to be back
jodie
of course I never believed that string and widestring are the same but for the proposes of yr code... it is
Anyway I was away from expert exchange for a while and it's good to be back
jodie
.. note that none of the Delphi VCL components actually deal in WideStrings, though. For example, if you do:
TLabel X;
WideString S;
S := 'something here';
X.Caption := S;
then it 'works', but only because the WideString gets converted to an AnsiString - you can't display unicode characters using this method...
TLabel X;
WideString S;
S := 'something here';
X.Caption := S;
then it 'works', but only because the WideString gets converted to an AnsiString - you can't display unicode characters using this method...
ASKER
andrewjb, yeah tell me about it... :(
https://www.experts-exchange.com/questions/20680377/unicode-in-windows98.html
https://www.experts-exchange.com/questions/20680377/unicode-in-windows98.html
var S: WideString;
begin ///
S := 'foo';
showmessage(S);
end;
would be better and depends on the version but in the latest versions string and widestring are the same
does it help?
JodieP