[fpc-devel] Bug in FPC and declaring distinct types

Graeme Geldenhuys graemeg.lists at gmail.com
Thu Sep 18 16:31:35 CEST 2008


On Thu, Sep 18, 2008 at 10:51 AM, Florian Klaempfl
<florian at freepascal.org> wrote:
>
> This is not true. The main purpose is to be able to overload
> functions/operators:
>
> type
>  TUTF8String = type ansistring;
>
> enables you to overload all procedure already defined for ansistrings with
> UTF8String functions but reusing ansistring support functionality and this
> is supported for years. Because nobody used this yet to make an utf-8 unit,
> I never took the unicode string support serious :)

OK, bare with me here... :-) Lets see if I understand it now.  "... =
type ...;" simply held or 'hints' to the compiler what overloaded
function to use - nothing more - no type safety!

type
 TUTF8String = type ansistring;

procedure DoTest(const s: ansistring); overload;
begin
end;

procedure DoTest(const s: TUTF8String); overload;
begin
end;

var
  a: String; // ansistring because I have {$H+} enabled
  u: TUTF8String;
begin
  a := '1234';
  u := a;      // allowed yes because utf8string is a ansistring
  u := 'aaaaa';
  a := u;      // allowed yes because ansistring is a utf8string

  { Due to type of u, compiler will know to call DoTest(utf8string) }
 DoTest(u);

  { Due to type of a, compiler will know to call DoTest(ansistring) }
 DoTest(a);

end.


Have I got this write so far?

So going with what you said about UTF8String type....  The idea was to
have overloaded copies of string functions for AnsiString, WideString
and UTF8String, all having different implementations.  Based on the
string type passed into a function, the compiler could make a better
choice as to which implementation of a function (eg: Copy(...) ) to
call.

If I got this right, then clearly the Delphi/Kylix help could have
explained distinct types MUCH better than they did. I (and many
others) understood it as having type safety as well - assignment
incompatible.

[...sorry, it's been a loooooong week for me...]

Regards,
 - Graeme -


_______________________________________________
fpGUI - a cross-platform Free Pascal GUI toolkit
http://opensoft.homeip.net/fpgui/



More information about the fpc-devel mailing list