[fpc-devel] Unicodestring branch, please test and help fixing
Ivo Steinmann
ivo_steinmann at gmx.net
Mon Sep 1 13:27:25 CEST 2008
Marco van de Voort schrieb:
> In our previous episode, Luiz Americo Pereira Camara said:
>
>>>> And use TNativeString for encoding agnostic purposes.
>>>>
>>> Well, really agnostic code should simply use "string" :)
>>>
>> Delphi is introducing the RawByteString type, that skips the auto
>> encoding conversion. I don't know where it fits in the upcoming unicode
>> schema. Anyway there's an example how to use it:
>> http://www.micro-isv.asia/2008/08/using-rawbytestring-effectively/
>>
>
> That's the lowlevel agnostic way. I'm talking more for purposes like classes
> libraries, that will want to use a native type on both conventions, but will
> generally operate on the strings on a relatively high level.
> _______________________________________________
> fpc-devel maillist - fpc-devel at lists.freepascal.org
> http://lists.freepascal.org/mailman/listinfo/fpc-devel
>
>
Why not creating a new kind of managed class, that is refcounted,
initialized, finalized, etc... like String type? then create a string
type on this managed class. So String is going to be a class. For for
unicode string you create a descendant of this class with unicode
implementations. This way it's still compatible to the baseclass String.
The managed class should follow these rules:
-------- EXAMPLE -----------
function Param(S: TManagedClass);
function VarParam(var S: TManagedClass);
function OutParam(out S: TManagedClass);
function ConstParam(const S: TManagedClass);
var
S, T: TManagedClass;
begin
{c} S := nil; // compiler code
{c} T := nil;
S := 'abcd';
{c} tmp := TManagedClass.Create('abcd');
{c} S := S.Assign(tmp); // Assign is a function that takes another
managed class to assign and returns a new instance or reference. (self
can be nil)
{c} tmp.Release;
Param(S);
{c} S.NewRef; // NewRef is a function that incrase the
{c} Param(S);
{c} S.Release;
VarParam(S);
{c} VarParam(S);
OutParam(S);
{c} S.Release;
{c} S := nil;
{c} OutParam(S);
ConstParam(S);
{c} ConstParam(S);
T := S;
{c} T := T.Assign(S);
T := S + 'abcd' + S;
{c} eg. TManagedClass.Append function....
{c} S.Release;
{c} T.Release;
end;
--------END ---------
I'm aware that a lot of these things could also implemented as
overloaded operators. But NOT the initialization, finalization and
parameter handling part.
Also Assign maybe a problem, because I need somehting like that:
operator := (var Dest: TManagedClass; Src: TManagedClass);
In case of assign, the destination pointer changes. but before I can
change the destination pointer, I have to release the reference. and
that's not possible with:
operator := (Src: TManagedClass) Dest: TManagedClass;
-Ivo
More information about the fpc-devel
mailing list