Jump to content

Kryvich

Members
  • Content Count

    279
  • Joined

  • Last visited

  • Days Won

    8

Posts posted by Kryvich


  1. So how you like a syntax Embarcadero finally choose for initialization / finalization of the custom managed records?

    type
      TMyRecord = record
        Value: Integer;
        class operator Initialize (out Dest: TMyRecord);
        class operator Finalize(var Dest: TMyRecord);
        class operator Assign (var Dest: TMyRecord; const [ref] Src: TMyRecord);
      end;

    Early in 2018 Marco showed a slightly different syntax.

    I personally would prefer something like

    type
      TMyRecord = record
        Value: Integer;
        operator Initialize;
        operator Finalize;
        operator Assign(const [ref] Src: TMyRecord);
      end;

    Then Dest would be replaced by Self.


  2. I would try to find out when used memory grows in size. After opening a certain form, or after compiling, or after starting the program, or after interrupting of execution Ctrl-F2...

    Try to temporary disable third party plugins and CodeInsight features (Error insight, Help insight).

    • Like 1

  3. Final conclusion after setting of UTF-8 as a default code page for Windows: if your program actively uses ANSI strings with national characters, you cannot just recompile the program and hope that it will work correctly. You will have to carefully check the code, and use AnsiStrings with a code page (i.e. AnsiString(1251)) or RawByteStrings where appropriate.


  4. @Tommi Prami Just a hope. I haven't access to the 10.4 beta.

     

    Note: When UTF-8 is used as a default code page in Windows, if you use national characters in a AnsiChar constant, they should be encoded in #$nn format. Otherwise you'll get "W1061 Narrowing given WideChar constant (#$0401) to AnsiChar lost information".

    program AnsiCharConst;
    {$APPTYPE CONSOLE}
    {$R *.res}
    const
      AnsiCharYo1: AnsiChar = 'Ё';
      AnsiCharYo2: AnsiChar = #$A8; // 'Ё' in ANSI 1251 Code Page;
    begin
      Writeln('#', Byte(AnsiCharYo1), ', #', Byte(AnsiCharYo2));
      Readln;
    end.

    This program shows: "#129, #168".

     

    • Like 1

  5. In Delphi 10.3.3 it's possible to write:

      TStaticCheck = class
        class procedure OverStatic; static; static; static; static;
      end;

    I don’t know, is it worth reporting to the issue tracker?

    The idea is taken from here: System.Generics.Collections.pas, TArray.BinarySearch<T>

    • Haha 1

  6. @Georgge Bakh FPC approach isn't wrong, but different.

    Other Points: 

    Quote

    1. The compiler parses a generic, but instead of generating code it stores all tokens in a token buffer inside the PPU file.
    2. The compiler parses a specialization; for this it loads the token buffer from the PPU file and parses that again. It replaces the generic parameters (in most examples "T") by the particular given type (e.g. LongInt, TObject).
    The code basically appears as if the same class had been written as the generic but with T replaced by the given type.

     

    Let's experiment: will do the specialization manually as the Wiki suggests.

    program ClassConstTest2;
    {$APPTYPE CONSOLE}
    {$R *.res}
    
    type
      TTest1 = class
        procedure Test();
      end;
    
      TTest2 = class(TTest1)
        procedure Test();
      end;
    
      TTestTest2 = class
        FTest: TTest2;
        procedure TestIt();
      end;
    
    procedure TTestTest2.TestIt();
    begin
      FTest := TTest2.Create();
      FTest.Test();
      readln;
    end;
    
    procedure TTest1.Test;
    begin
      Writeln('TTest1.Test');
    end;
    
    procedure TTest2.Test;
    begin
      Writeln('TTest2.Test');
    end;
    
    var
      Test2: TTestTest2;
    
    begin
      Test2 := TTestTest2.Create;
      Test2.TestIt;
    end.

    This code outputs TTest2.Test

×