Island/Delphi simple App does not work

Hi,

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.

An exception occurred in DelphiApp1, thread 0C74

Type: AccessViolationException

Message:

Code c0000005

Call Stack:

0000000536880687 @System@SysFreeMem$qqrpv rtl100.bpl
0000000000456641 DelphiObjectToString DelphiApp1.exe
0000000000262013 DelphiApp1.Program.Main DelphiApp1.exe (program.pas, line 10)
0000000000200712 __island_force_release DelphiApp1.exe
0000000000249484 RemObjects.Elements.System..main DelphiApp1.exe (windowshelpers.pas, line 1707)
0000000000250072 RemObjects.Elements.System..mainCRTStartup DelphiApp1.exe (windowshelpers.pas, line 1728)
0000001968504009 BaseThreadInitThunk KERNEL32.DLL
0000002003993262 RtlGetAppContainerNamedObjectPath
0000002003993214 RtlGetAppContainerNamedObjectPath

Is the Island/Delphi not yet usable ?

Cheers, Adrian.

My apologies for the delay we’ll take a look.

I assume an empty’is Main with just eg writeLn('The magic happens here.'); is fine?

—marc

Logged as bugs://E27591.

you shouldn’t.

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"

Runs fine for me too, with Delphi 12 packages; gotta find and install Delphi 13 to test if the issue is specific to that version…

bugs://E27591 was closed as cannot reproduce (for now).