Forum: Object-Pascal / Delphi-Language
Delphi
by uligerhardt,
3. Dez 2012
Don't use PCardinal and Inc(P) because this would limit you to elements with the same size as Cardinal: if P is of type PCardinal, then it points to an element of SizeOf(Cardinal) bytes. If you then do Inc(P) you advance P by SizeOf(Cardinal) bytes. But you want P to point to elements of size ASize bytes, so use PByte and Inc(P, ASize) (as I already wrote :stupid:).
Forum: Object-Pascal / Delphi-Language
Delphi
by uligerhardt,
2. Dez 2012
With Furtbichler's routine signature you could have something like
procedure SwapArrayElements(aStartElement : Pointer; aElementSize, aElementCount : Integer);
var
p: PByte;
begin
p := AStartElement; // p points to first element
Inc(p, aElementSize); // Now p points to second element
Move(p^, ..., aElementSize); // Moves the element p points to
end;
(NB: These are only some...
Forum: Object-Pascal / Delphi-Language
Delphi
by uligerhardt,
2. Dez 2012
What is a pointer? The parameter to your routine or the array element?
Forum: Object-Pascal / Delphi-Language
Delphi
by uligerhardt,
2. Dez 2012
That is what generics are for, but they are available only from Delphi 2009 and up.