Jump to content

Chris Rolliston

Members
  • Content Count

    5
  • Joined

  • Last visited

Community Reputation

1 Neutral

Recent Profile Visitors

The recent visitors block is disabled and is not being shown to other users.

  1. Chris Rolliston

    Record / Class

    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. Chris Rolliston

    [BUG] HTTPS support in 64bits - Access Violation

    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. Chris Rolliston

    .Net VCL for Delphi

    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. Chris Rolliston

    Anon methods passed as event handlers?

    By the by, this historical piece is quite an amusing read: https://web.archive.org/web/20120627043929/http://java.sun.com/docs/white/delegates.html Sun's reply to Microsoft adding delegate types to its Windows-centric version of Java (Visual J++ being Anders Hejlsberg's main project in between Delphi and C# I think...?).
  5. Chris Rolliston

    Anon methods passed as event handlers?

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