AGB  ·  Datenschutz  ·  Impressum  







Anmelden
Nützliche Links
Registrieren
Thema durchsuchen
Ansicht
Themen-Optionen

How to reverse array of any type?

Ein Thema von WojTec · begonnen am 2. Dez 2012 · letzter Beitrag vom 3. Dez 2012
 
Benutzerbild von uligerhardt
uligerhardt

Registriert seit: 19. Aug 2004
Ort: Hof/Saale
1.735 Beiträge
 
Delphi 2007 Professional
 
#15

AW: Re: How to reverse array of any type?

  Alt 3. Dez 2012, 13:16
Delphi-Quellcode:
procedure ReverseArray(AData: Pointer; const ASize, ACount: Integer);
var
  Left, Right, Temp: Integer;
  P: PCardinal;
begin
  P := AData;

  Left := 0;
  Right := ACount;

  Result := Left < Right;

  if Result then
  begin
    while (Left < Right) do
    begin
      {Temp := AValues[Left];
      AValues[Left]  := AValues[Right];
      AValues[Right] := Temp;}
  // Don't know how to exchange with pointers :(
      //Move(P^, ..., ASize); // Don't know how if I don't know types ????????

      Inc(P);
      Inc(Left);
      Dec(Right);
    end;
  end;
end;
I don't know how replace part should works. Above is form reversing knowed type array.
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 ).
Uli Gerhardt
  Mit Zitat antworten Zitat
 


Forumregeln

Es ist dir nicht erlaubt, neue Themen zu verfassen.
Es ist dir nicht erlaubt, auf Beiträge zu antworten.
Es ist dir nicht erlaubt, Anhänge hochzuladen.
Es ist dir nicht erlaubt, deine Beiträge zu bearbeiten.

BB-Code ist an.
Smileys sind an.
[IMG] Code ist an.
HTML-Code ist aus.
Trackbacks are an
Pingbacks are an
Refbacks are aus

Gehe zu:

Impressum · AGB · Datenschutz · Nach oben
Alle Zeitangaben in WEZ +1. Es ist jetzt 14:57 Uhr.
Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
LinkBacks Enabled by vBSEO © 2011, Crawlability, Inc.
Delphi-PRAXiS (c) 2002 - 2023 by Daniel R. Wolf, 2024 by Thomas Breitkreuz