Re: copy one character from a string.



MLian wrote:
> That did the trick.
> I'd forgot the Setlength statement.

Do also notice that the string type has a copy-on-change functionality:

var
S1,
S2: string;
begin
S1:='Some incredibly long string, maybe MB''s of length';
S2:=S1; // S2 now points to S1, only one instance exists in memory. The
string has a refcount of 2.
S2[1]:='X'; // S2 is now copied into a newly allocated string, both S1 and
S2 having a refcount of 1.
--
Bjørge
bjorge@xxxxxxxxxxxx


.



Relevant Pages

  • Re: Fastcode Non-Nil Zero Length String Validation
    ... Some value is present in the refcount field. ... are the string data. ... garbage and returns an empty string. ...
    (borland.public.delphi.language.basm)
  • Fastcode Trim Refcount Bump Validation
    ... We had a little discussion about the validity of bumping the refcount ... compared to doing an actual copy of the string if there is nothing to trim. ...
    (borland.public.delphi.language.basm)
  • Re: Fastcode Trim B&V 0.3.0
    ... Is it not normal valid AnsiString ... Should we have a validation for the result string having a refcount of 1? ...
    (borland.public.delphi.language.basm)
  • Re: Fastcode Trim B&V 0.6.1
    ... copy of the string (as the RTL function does) is acceptable. ... that's why the RefCount is there). ...
    (borland.public.delphi.language.basm)
  • Re: Fastcode Non-Nil Zero Length String Validation
    ... What is the string data? ... The refcount? ... and no reference count, no chars, no terminator constructed. ...
    (borland.public.delphi.language.basm)