Jump to content

Alexander Elagin

Members
  • Content Count

    198
  • Joined

  • Last visited

  • Days Won

    6

Posts posted by Alexander Elagin


  1. 59 minutes ago, dummzeuch said:

    ... or simply add the _AddRef, _Release (wasn't there a 3rd one?) methods required for an interface implementation to your ancestor class and let them do nothing.

    The third one is QueryInterface:

    ....
    
     protected
        function QueryInterface({$IFDEF FPC}constref{$ELSE}const{$ENDIF} IID: TGUID;  out Obj): HResult; stdcall;
        function _AddRef: Integer; stdcall;
        function _Release: Integer; stdcall;
    
    ....
    
    
    function TMyClass.QueryInterface({$IFDEF FPC}constref{$ELSE}const{$ENDIF}  IID: TGUID; out Obj): HResult; stdcall;
    begin
      if GetInterface(IID, Obj) then
        Result := S_OK
      else
        Result := E_NOINTERFACE;
    end;
    
    function TMyClass._AddRef: Integer; stdcall;
    begin
      Result := -1;
    end;
    
    function TMyClass._Release: Integer; stdcall;
    begin
      Result := -1;
    end;

    Implement these three functions and you have a nice class with interfaces and without any reference counting.


  2. 27 minutes ago, vfbb said:

    Although I don't particularly like this design, you can make a descendant of TInterfacedPersistent, your class will not be arc and will be able to implement interfaces.

    
    TBaseFrame = class(TInterfacedPersistent)

     

    Or better inherit from TSingletonImplementation (I wonder who decided to give the base non-ARC interfaced object this misleading name...)


  3. 12 minutes ago, Mike Torrettinni said:

    Aha, I see that Fastmm was integrated in Delphi in 2007(?), so I don't really need Fastmm in my projects with 10.2.3, I guess.

     

    If you want to get the most of FastMM (different configurations for debug/release, fine tuning of settings) you still need the standalone version. The bundled one is a "good middle ground" but there always are options to get more...

    • Like 1

  4. This function exists also in 10.1, but for obvious reasons there is no trace of this code in Delphi XE. Somebody probably used some black magic to force scaling engine into the two decades old and pretty stable code of the Forms unit, but had to put duct tape here and there to make it work. No doubt that the IDE theming used even more glue and tape, that's why the themed IDE is a slow monster.


  5. FreePascal version of the same function in mode O1 (quick optimization):

     

    function foo(I: Integer): Integer;
    begin
      case I of
        0: Exit(random(255));
        1: Exit(3);
        2: Exit(4);
        3: Exit(5);
        4: Exit(6);
        5: Exit(7);
      else
        Exit(0);
      end;
    end;

     

    FPC_Test.lpr:50                           begin
    00000001000018C0 55                       push   %rbp
    00000001000018C1 4889e5                   mov    %rsp,%rbp
    00000001000018C4 488d6424d0               lea    -0x30(%rsp),%rsp
    00000001000018C9 894df8                   mov    %ecx,-0x8(%rbp)
    FPC_Test.lpr:51                           case I of
    00000001000018CC 89c8                     mov    %ecx,%eax
    00000001000018CE 85c9                     test   %ecx,%ecx
    00000001000018D0 0f8c6e000000             jl     0x100001944 <FOO+132>
    00000001000018D6 85c0                     test   %eax,%eax
    00000001000018D8 741e                     je     0x1000018f8 <FOO+56>
    00000001000018DA 83e801                   sub    $0x1,%eax
    00000001000018DD 7429                     je     0x100001908 <FOO+72>
    00000001000018DF 83e801                   sub    $0x1,%eax
    00000001000018E2 7430                     je     0x100001914 <FOO+84>
    00000001000018E4 83e801                   sub    $0x1,%eax
    00000001000018E7 7437                     je     0x100001920 <FOO+96>
    00000001000018E9 83e801                   sub    $0x1,%eax
    00000001000018EC 743e                     je     0x10000192c <FOO+108>
    00000001000018EE 83e801                   sub    $0x1,%eax
    00000001000018F1 7445                     je     0x100001938 <FOO+120>
    00000001000018F3 eb4f                     jmp    0x100001944 <FOO+132>
    00000001000018F5 0f1f00                   nopl   (%rax)
    FPC_Test.lpr:52                           0: Exit(random(255));
    00000001000018F8 b9ff000000               mov    $0xff,%ecx
    00000001000018FD e8bed70000               callq  0x10000f0c0 <SYSTEM_$$_RANDOM$LONGINT$$LONGINT>
    0000000100001902 8945f4                   mov    %eax,-0xc(%rbp)
    0000000100001905 eb45                     jmp    0x10000194c <FOO+140>
    0000000100001907 90                       nop
    FPC_Test.lpr:53                           1: Exit(3);
    0000000100001908 c745f403000000           movl   $0x3,-0xc(%rbp)
    000000010000190F eb3b                     jmp    0x10000194c <FOO+140>
    0000000100001911 0f1f00                   nopl   (%rax)
    FPC_Test.lpr:54                           2: Exit(4);
    0000000100001914 c745f404000000           movl   $0x4,-0xc(%rbp)
    000000010000191B eb2f                     jmp    0x10000194c <FOO+140>
    000000010000191D 0f1f00                   nopl   (%rax)
    FPC_Test.lpr:55                           3: Exit(5);
    0000000100001920 c745f405000000           movl   $0x5,-0xc(%rbp)
    0000000100001927 eb23                     jmp    0x10000194c <FOO+140>
    0000000100001929 0f1f00                   nopl   (%rax)
    FPC_Test.lpr:56                           4: Exit(6);
    000000010000192C c745f406000000           movl   $0x6,-0xc(%rbp)
    0000000100001933 eb17                     jmp    0x10000194c <FOO+140>
    0000000100001935 0f1f00                   nopl   (%rax)
    FPC_Test.lpr:57                           5: Exit(7);
    0000000100001938 c745f407000000           movl   $0x7,-0xc(%rbp)
    000000010000193F eb0b                     jmp    0x10000194c <FOO+140>
    0000000100001941 0f1f00                   nopl   (%rax)
    FPC_Test.lpr:59                           Exit(0);
    0000000100001944 c745f400000000           movl   $0x0,-0xc(%rbp)
    000000010000194B 90                       nop
    FPC_Test.lpr:61                           end;
    000000010000194C 8b45f4                   mov    -0xc(%rbp),%eax
    000000010000194F 90                       nop
    0000000100001950 488d6500                 lea    0x0(%rbp),%rsp
    0000000100001954 5d                       pop    %rbp
    0000000100001955 c3                       retq   
    

    Judge it yourself :classic_tongue:

     

     

     


  6. 1 hour ago, Juan C.Cilleruelo said:

    These days I've received the offer to renovate Delphi Professional Subscription, but this time don't come with the FireDAC Add-On, like past years. 

    Use UniDAC, which is not too expensive and is a good independent alternative to FireDAC. It also supports Lazarus and older versions of Delphi. Switching from FireDAC is not difficult.

    https://www.devart.com/unidac/

     

    • Like 1
    • Sad 1

  7. 45 minutes ago, Fr0sT.Brutal said:

    Rule #1. Always use standardized format for string representation. For dates it could be ISO 8601 or something custom but explicitly forced! F.ex. with FormatDateTime(dt, CommonFormat). The same with floats.

    There are two great functions in the DateUtils module: DateToISO8601 and ISO8601ToDate. They can save a lot of pain when it is needed to store date/time in text files.


  8. 8 minutes ago, Bill Meyer said:

    But if my manager determines we're not to do that, then I'd be stuck.

    If the manager assumes the responsibility, then just have a written document signed by him - be it a specification or a simple memo. If things go wrong, you'll have you covered.


  9. It is strange that 10.4 does not show access violation here while the error is obvious:

     

    c1 := 'A';

    p := PChar(c1); // wrong explicit conversion: widechar to integer to pointer.

    // Now p is a pointer to the memory location at the address 0x00000041 - that is, the value of Ord(A)

    showmessage(p^); // here p^ points to memory location at 0x00000041, obviously not was meant by the author


  10. So if I am the Primary Contact (as I paid the bill myself) I still have to assign myself somewhere as an Authorized Contact? Damn, the Embarcadero's sales model does not change with years, they are targeting businesses, not developers. And don't remind me about all this reseller-only distribution and obligatory quote request for updates ☠️...

    • Like 3
×