I just wanted to play with Island/Delphi support, but I can’t get the smallest thinkable App to run. I have this (almost as in the docs).
namespace DelphiApp1;
uses Delphi.Classes, Delphi.System;
type
Program = class
public
class method Main();
begin
writeLn('The magic happens here.');
var lList := new TStringList;
writeLn('created');
var s: DelphiAnsiString := 'Hello'; // why do I need an DelphiAnsiString here when compiled with Delphi 13 SDK ?
lList.Add(s); // this crashes at runtime with SDK 13 and complains at compile time when s is a DelphiString !
writeLn('added');
writeLn(lList.Text);
lList.Free;
var l = new TStringList;
writeLn('created');
l.Add('Hello');
l.Add('World');
writeLn('added');
l.Delimiter:= Delphi.System.Char('|'); // note here is a char accepted which doesn't match to DelphiAnsiString with SDK 13
writeLn(l.DelimitedText);
l.Free;
writeLn('done');
l:= nil;
lList:= nil;
end;
end;
end.
I tried this with the Delphi 13 runtime, where String is a UnicodeString in Delphi, not an AnsiString. I guess this causes the crash. IMO this shouldn’t compile when I use the Delphi 13 SDK.
When I try it with the an older Delphi 2007 SDK it compiles as well (this time this is ok, because String is AnsiString), but crashes after the program has finished.
I’m not set up for Delphi 13 on my machine right now (will check tomorrow), but for Delphi 12/Windows/x86_84, this compiles clean:
namespace ConsoleApplication2;
uses
Delphi.System.Classes;
type
Program = class
public
class method Main();
begin
writeLn('The magic happens here.');
var lList := new TStringList;
writeLn('created');
var s: DelphiString := 'Hello';
lList.Add(s); // this crashes at runtime with SDK 13 and complains at compile time when s is a DelphiString !
writeLn('added');
writeLn(lList.Text);
lList.Free;
var l := new TStringList;
writeLn('created');
l.Add('Hello');
l.Add('World');
writeLn('added');
l.Delimiter:= Delphi.System.Char('|'); // note here is a char accepted which doesn't match to DelphiAnsiString with SDK 13
writeLn(l.DelimitedText);
l.Free;
writeLn('done');
l:= nil;
lList:= nil;
end;
end;
end.
You’ll want a DelphiString (which is DelphiUnicodeString), not a DelphiAnsiString, as that’s the default string type in later Delphis…
just
var s := 'Hello';
lList.Add(s);
works too, s will be an IslandString, but it will auto-cast when passed to a method that expects a DelphiString…
For the crash with passing an AnsiString to Add, i’ll have to test that tomorrow as well (i’m not on Windows right now); it should require an explicit cast to up-convert from AnsiString to UnicodeString, iirc…
It actually does fail to compile for me, Delphi 12:
var s: DelphiAnsiString := 'Hello' as DelphiAnsiString;
lList.Add(s); // E406 No overloaded method "Add" with these parameters on type "TStringList", best matching overload is "Add(S: Delphi.System.UnicodeString): Int32"
// H3 parameter 1 is "DelphiAnsiString" should be "Delphi.System.UnicodeString"