Jump to content

Kryvich

Members
  • Content Count

    402
  • Joined

  • Last visited

  • Days Won

    8

Posts posted by Kryvich


  1. 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

  2. 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.


  3. @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

  4. 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

  5. @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


  6. I would like to see in some future version of Delphi:

    • Like 1

  7. @aehimself Or using generics:

      TMyApplication2<T: TBaseEncoder> = class
      strict private
        _myencoder: TBaseEncoder;
      public
        constructor Create;
      end;
    
    constructor TMyApplication2<T>.Create;
    begin
      inherited Create;
      _myencoder := TBaseEncoderClass(T).Create;
    end;
    
    begin
      var MyApp1 := TMyApplication2<TBaseEncoder>.Create;
      Writeln(MyApp1.ClassName);
      var MyApp2 := TMyApplication2<TEncoderV3>.Create;
      Writeln(MyApp2.ClassName);
    end.

     

×