Posts

Showing posts with the label Delphi 2009

Copy Const Array To Dynamic Array In Delphi

Answer : This will copy constAry1 to dynAry . SetLength(dynAry, Length(constAry1)); Move(constAry1[Low(constAry1)], dynAry[Low(dynAry)], SizeOf(constAry1)); function CopyByteArray(const C: array of Byte): TByteDynArray; begin SetLength(Result, Length(C)); Move(C[Low(C)], Result[0], Length(C)); end; procedure TFormMain.Button1Click(Sender: TObject); const C: array[1..10] of Byte = (1, 2, 3, 4, 5, 6, 7, 8, 9, 10); var D: TByteDynArray; I: Integer; begin D := CopyByteArray(C); for I := Low(D) to High(D) do OutputDebugString(PChar(Format('%d: %d', [I, D[I]]))); end; procedure TFormMain.Button2Click(Sender: TObject); const C: array[1..10, 1..10] of Byte = ( (1, 2, 3, 4, 5, 6, 7, 8, 9, 10), (1, 2, 3, 4, 5, 6, 7, 8, 9, 10), (1, 2, 3, 4, 5, 6, 7, 8, 9, 10), (1, 2, 3, 4, 5, 6, 7, 8, 9, 10), (1, 2, 3, 4, 5, 6, 7, 8, 9, 10), (1, 2, 3, 4, 5, 6, 7, 8, 9, 10), (1, 2, 3, 4, 5, 6, 7, 8, 9, 10), (1, 2, 3, 4, 5, 6, 7, 8, 9, 10), (1, 2, ...