vfbb 285 Posted February 16, 2021 Sometimes I come across some delphi language enhancements that are undocumented or are poorly documented. In the last few years docwiki has improved a lot, but there are still undocumented cases, such as accessing an item in an array just by declaring a property, without any method: TipGeolocation = record private FCoordinates: array[0..1] of Double; public property Latitude: Double read FCoordinates[0] write FCoordinates[0]; property Longitude: Double read FCoordinates[1] write FCoordinates[1]; end; Share here any enhancements to the delphi language that you have discovered but are not documented. 4 Share this post Link to post
vfbb 285 Posted February 16, 2021 Virtual interfaces: to create an object that support an interface in run time. See System.Rtti.TVirtualInterface Share this post Link to post
David Heffernan 2345 Posted February 16, 2021 49 minutes ago, vfbb said: Share here any enhancements to the delphi language that you have discovered but are not documented. The entire language is essentially undocumented. There is no formal specification, no documented grammar etc. 2 Share this post Link to post
balabuev 102 Posted February 16, 2021 (edited) 13 hours ago, vfbb said: such as accessing an item in an array just by declaring a property, without any method Similarly, should work with records: type TMy = class private FPoint: TPoint; public property X: Integer read FPoint.X write FPoint.X; property Y: Integer read FPoint.Y write FPoint.Y; end; This can even be mixed with static arrays: type TMyData = record Points: array[0..1] of TPoint; end; TMy = class private FData: TMyData; public property X: Integer read FData.Points[1].X write FData.Points[1].X; property Y: Integer read FData.Points[1].Y write FData.Points[1].Y; end; Edited February 17, 2021 by balabuev 2 Share this post Link to post
Der schöne Günther 316 Posted February 16, 2021 1 hour ago, David Heffernan said: The entire language is essentially undocumented. There is no formal specification, no documented grammar etc. Not highly scientific, but better than nothing: Delphi Language Reference - RAD Studio (embarcadero.com) Share this post Link to post
David Heffernan 2345 Posted February 16, 2021 (edited) 8 minutes ago, Der schöne Günther said: Not highly scientific, but better than nothing: Delphi Language Reference - RAD Studio (embarcadero.com) Obviously I know this and have read it plenty of times. But it's way short of a formal specification. Just read the topic for properties. What does fieldOrMethod mean? It's not precisely defined anywhere. The entire language documentation is like that. Just a little imprecise. Edited February 16, 2021 by David Heffernan Share this post Link to post
Remy Lebeau 1393 Posted February 17, 2021 Undocumented intrinsic routines Undocumented Delphi routines Undocumented Delphi record alignment directive Just to name a few. I know there are other sites that document more, I just don't have the time to hunt them down. 3 1 Share this post Link to post
Fr0sT.Brutal 900 Posted February 17, 2021 (edited) "Static variables" inside procedures function Counter: Integer; {$J+} const I: Integer = 0; {$J-} begin I := I + 1; Result := I; end; When you declare a const with a type, Delphi allocates memory for the constant. The program can change the value of the “constant,” just as though it were a variable. The difference between a typed constant and a local variable is that a typed constant in a subroutine keeps its value across subroutine calls. If you disable the $WriteableConst directive, you can prevent any assignments to a typed constant, thereby making the constant truly constant. There is no substitute for typed constants in a subroutine, though, so disable $WriteableConst with care. Disable only specific constants whose value you want to protect, and do not disable this directive globally in a project or an entire file. Short init of record constants type TR = record a: string; b: string; end; Const TR_Empty: TR = (); Const TR_A: TR = (a: 'foo'); (not undocumented but non-obvious ones) Edited February 17, 2021 by Fr0sT.Brutal 4 Share this post Link to post