<div dir="ltr"><div dir="ltr">On Mon, Jul 8, 2019 at 3:47 PM Ben Grasset <<a href="mailto:operator97@gmail.com">operator97@gmail.com</a>> wrote:<br></div><div class="gmail_quote"><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div dir="ltr"><div dir="ltr">On Mon, Jul 8, 2019 at 2:22 PM Ryan Joseph <<a href="mailto:genericptr@gmail.com" target="_blank">genericptr@gmail.com</a>> wrote:<br></div><div class="gmail_quote"><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">
and it will actually write to the actual record in the array and not a returned copy. However due to how the properties are currently structured this means we can’t use the setter without passing pointers<br></blockquote><div><br></div><div>Ah, I see what you mean. Note you can at least work around this for now with operator overloading:</div></div></div></blockquote><div><br></div><div>Also, here's a longer (but much better because it doesn't require the data type provided by the user to itself be directly assignable to a pointer) version of that:</div><div><br></div><div>program Example;<br><br>{$mode Delphi}{$H+}<br><br>uses SysUtils;<br><br>type<br> PVec3F = ^TVec3F;<br><br> TVec3F = record<br> X, Y, Z: Single;<br> end;<br><br>type<br> TList<T> = record<br> public type<br> PT = ^T;<br> TConverter = record<br> V: PT;<br> class operator Implicit(constref From: T): TConverter; inline;<br> class operator Implicit(const From: PT): TConverter; inline;<br> class operator Implicit(constref From: TConverter): PT; inline;<br> end;<br> strict private<br> FData: array of TConverter;<br> private<br> function GetItem(const I: PtrUInt): TConverter; inline;<br> procedure SetItem(const I: PtrUInt; const Val: TConverter); inline;<br> function GetLength: PtrInt; inline;<br> procedure SetLength(const I: PtrInt); inline;<br> public<br> property Items[const I: PtrUInt]: TConverter read GetItem write SetItem; default;<br> property Length: PtrInt read GetLength write SetLength;<br> end;<br><br> class operator TList<T>.TConverter.Implicit(constref From: T): TConverter;<br> begin<br> Result.V := @From;<br> end;<br><br> class operator TList<T>.TConverter.Implicit(const From: PT): TConverter;<br> begin<br> Result.V := From;<br> end;<br><br> class operator TList<T>.TConverter.Implicit(constref From: TConverter): PT;<br> begin<br> Result := From.V;<br> end;<br><br> function TList<T>.GetItem(const I: PtrUInt): TConverter;<br> begin<br> if I < System.Length(FData) then<br> Result := FData[I]<br> else<br> Result := nil;<br> end;<br><br> procedure TList<T>.SetItem(const I: PtrUInt; const Val: TConverter);<br> begin<br> if I < System.Length(FData) then<br> FData[I] := Val;<br> end;<br><br> function TList<T>.GetLength: PtrInt;<br> begin<br> Result := System.Length(FData);<br> end;<br><br> procedure TList<T>.SetLength(const I: PtrInt);<br> begin<br> System.SetLength(FData, I);<br> end;<br><br>const<br> DEFAULT_VEC3F: TVec3F = (<br> X: 0.0;<br> Y: 0.0;<br> Z: 0.0;<br> );<br><br>var<br> PVec: PVec3F;<br> VecList: TList<TVec3F>;<br><br>begin<br> VecList.Length := 2;<br><br> // So, you can directly assign to the list by value...<br> VecList[0] := DEFAULT_VEC3F;<br><br> // Or via a pointer...<br> VecList[1] := @DEFAULT_VEC3F;<br><br> // And directly assign *from* the list to a pointer...<br> PVec := VecList[0];<br> with PVec^ do begin<br> X := 2.0;<br> Y := 4.0;<br> Z := 6.0;<br> end;<br> with PVec^ do<br> WriteLn(Format('[%f %f %f]', [X, Y, Z]));<br><br> // Or just do this<br> with VecList[0].V^ do begin<br> X := 2.0;<br> Y := 4.0;<br> Z := 6.0;<br> end;<br><br> //And this<br> with VecList[0].V^ do<br> WriteLn(Format('[%f %f %f]', [X, Y, Z]));<br>end.<br></div></div></div>