[fpc-devel] new string - question on usage

Sven Barth pascaldragon at googlemail.com
Wed Oct 12 16:59:51 CEST 2011


Am 12.10.2011 16:46, schrieb Michael Schnell:
> On 10/12/2011 04:23 PM, Sven Barth wrote:
>>
>> There was some discussion about how to handle var parameters, but I
>> don't remember the outcome anymore. AFAIK Delphi issues a compile
>> error (I don't know for sure though).
> Options are:
>
> - compiler error
> - compiler warning
> - runtime exception
> - conversion to and fro
> - just passing the pointer (making creating an intersexual string easy)
>
>
> We will see :)

So... now you got me to start my Delphi XE and I then noticed that I had 
already written a small test project to test this ^^

Here is the code:

=== source begin ===

program strvartest;

{$APPTYPE CONSOLE}

uses
   SysUtils;

type
   CyrillicString = type AnsiString(1251);
   LatinString = type AnsiString(1252);
   TestString = type AnsiString(65001);

procedure Test(var aStr: CyrillicString);
begin

end;

var
   s: LatinString;
begin
   s := 'Foo';
   Test(s);
end.

=== source end ===

Result:
[DCC Fehler] strvartest.dpr(22): E2033 Die Typen der tatsächlichen und 
formalen Var-Parameter müssen übereinstimmen

For those that don't speak German (so shouldn't be you, Michael) a free 
translation:
[DCC Error] strvartest.dpr(22): E2033 The types of the actual and formal 
var-paramaters have to match

So at least Delphi uses the compiletime error approach. So it should be 
likely that FPC follows that approach.

Regards,
Sven



More information about the fpc-devel mailing list