Lifetimestrategy(Manual)

In the docs you show string variable declaration: var s : lifetimestrategy(manual) String := …; But how to initialize this string variable? Any variants lead to compilation error.

      var s2 : lifetimestrategy(Manual) String := Manual<String>('hello');
      var s3 : lifetimestrategy(Manual) String := new Manual<String>('hello');

      var s4 : Manual<String> := 'hello';
      var s5 : Manual<String> := Manual<String>('hello');
      var s6 : Manual<String> := new Manual<String>('hello');

E: Type mismatch, cannot assign “String” to “String” [C:\Users\Alexey\Documents\RemObjects Software\Elements\Water\ConsoleApplication\Program.pas (9)]
E: Cannot cast from “String” to “Manual” [C:\Users\Alexey\Documents\RemObjects Software\Elements\Water\ConsoleApplication\Program.pas (10)]
E: Type “String” has no accessible constructors [C:\Users\Alexey\Documents\RemObjects Software\Elements\Water\ConsoleApplication\Program.pas (11)]
E: Type mismatch, cannot assign “String” to “Manual” [C:\Users\Alexey\Documents\RemObjects Software\Elements\Water\ConsoleApplication\Program.pas (13)]
E: Cannot cast from “String” to “Manual” [C:\Users\Alexey\Documents\RemObjects Software\Elements\Water\ConsoleApplication\Program.pas (14)]
E: Type “String” has no accessible constructors [C:\Users\Alexey\Documents\RemObjects Software\Elements\Water\ConsoleApplication\Program.pas (15)]

Unfortunately, String and array are the only types that don’t support lifetime management, because they are compiler generated. Is there any reason you want to use manual lifetime management on strings?

Just a test of new Oxygene feature :wink: And your docs uses the string type.

i’ll get the docs fixed, thanx!

so this will work in the next version:

namespace ConsoleApplication1067;

type
  MyString = public class
  private
  
  public
    constructor(aval: String); begin writeLn('ct'); end;
    finalizer;
    begin 
      writeLn('fin');
    end;
  end;
  Program = class
  public

    class method Main(args: array of String): Int32;
    begin
      writeLn('Entry');
      var s3 : lifetimestrategy(Manual) MyString := new Manual<MyString>('hello');
      var s6 : Manual<MyString> := new Manual<MyString>('hello');
      writeLn('Freeing');
      Manual.Free(s3);
      Manual.Free(s6);
      writeLn('Done');
    end;

  end;

end.

(I’ve added the Free api)