Jump to content

Chris Rolliston

Members
  • Content Count

    5
  • Joined

  • Last visited

Posts posted by Chris Rolliston


  1. 37 minutes ago, PatV said:

    How should I write it then ?

    What are you aiming to achieve...? Returning a pointer to Self doesn't give any obvious benefit - if the rTxt instance is statically defined, the validity of a pointer to it will remain restricted to the scope of the instance variable. In other words, this sort of code is invalid -

    function Foo(const Value: string): pTxt;
    var
      Inst: rTxt;
    begin
      Result := Inst.WriteValue(Value);
    end;
    
    procedure Test;
    var
      Ptr: pTxt;
    begin
      Ptr := Foo('Bad code - if the next bit "works", it will only be by luck');
      ShowMessage(Ptr.AsText);
    end;

    Conversely if rTxt is dynamically allocated (New and Dispose standard procedures), then by definition you lose the 'lazy' benefit you hoped to achieve. If your intent was that WriteValue should return a new instance, then (as David said) the method needs to be a class static method (or a constructor), and return the instance type (not a pointer):

    type
      fTxt = record
      // ...
        class function WriteValue(const Value: String): fTxt; static;
      end;
    
    class function fTxt.WriteValue(const Value: String): fTxt;
    begin
      Result.FValue := Value;
    end;
    
    function Foo(const Value: string): fTxt;
    begin
      Result := fTxt.WriteValue(Value);
    end;
    
    procedure Test;
    var
      Inst: fTxt;
    begin
      Inst := Foo('OK code - if next bit works genuinely');
      ShowMessage(Inst.AsText);
    end;

     


  2. 13 hours ago, Marcelo Jaloto said:

    Hello
    I discovered the bug and the solution.


    A pointer is 4 bytes in 32 bits and 8 bytes in 64 bits.

     

    See more at :
    http://docwiki.embarcadero.com/RADStudio/Rio/en/Converting_32-bit_Delphi_Applications_to_64-bit_Windows

     

    The IcsWireFmtToStrList method of the OverbyteIcsUtils unit had a problem moving characters with Move without regard to the number of bytes.

     

    Wrong:

    
    Move (Buffer [offset], AStr [1], mylen);

     

    Correct:

    
    Move (Buffer [offset], AStr [1], mylen * SizeOf (TBytes));

     

    The Len parameter comes with the value 12.

    This correction cannot be correct. TBytes is a reference type (i.e. thinly-veiled pointer) to an array of byte values; Move copies actual data (i.e. the stuff that a reference type references), against units of the actual data. In addition, this code uses Move to copy into an AnsiString, which is also a reference type to an array of byte-sized elements. Ergo, an element size of 1 is correct, being what both SizeOf(Byte) (i.e. the element type for a TBytes) and SizeOf(AnsiChar) (the element type for an AnsiString) both are.


  3. Hmm, beyond DataGridView (pretty nice for a default grid control), I think I'd personally take pretty much any VCL control over its WinForms equivalent.

     

    Given you have the plumbing, have you considered wrapping a newer .NET UI tech, or even UWP...?


  4. 10 minutes ago, Rudy Velthuis said:

    That's cool. ISTM that for Delphi, it would mean quite a few changes in the compiler.

     

    And well, I still don't see why it should be done.

    C# event types were the equivalent of method reference types in Delphi in the first place (in fact, even more heavyweight given the multicasting support), so a Delphi-style problem of how to shoehorn anonymous methods to events, when anonymous methods were added in C# 2.0, didn't arise.

     

    IMO (and I think this is in agreement with you?), the only way to do this truly cleanly in Delphi would be to switch the event type from method pointers to method references (the latter already support at a syntax level assignments of regular methods and standalone routines). However, that would be a complete no-no for VCL backwards compatibility.

×