AGB  ·  Datenschutz  ·  Impressum  







Anmelden
Nützliche Links
Registrieren
Zurück Delphi-PRAXiS Programmierung allgemein Programmieren allgemein Datei mit dynamischen Array einlesen

Datei mit dynamischen Array einlesen

Ein Thema von lagalex · begonnen am 18. Feb 2013 · letzter Beitrag vom 19. Feb 2013
Antwort Antwort
lagalex

Registriert seit: 16. Jan 2011
7 Beiträge
 
#1

AW: Datei mit dynamischen Array einlesen

  Alt 19. Feb 2013, 09:35
Hallo,
Vielen Dank für all die Hilfestellungen und Denkanregungen, hab zwar das Problem noch immer nicht durchschaut, bin aber so glaube ich zumindest mal einen Schritt weiter...

- Hab den Vorschlag mit ReadBuffer() umgesetzt
- Beim Ausführen bekomme ich einen RunError 203, also einen Heap Overflow

Anbei ist die shp-Datei als zip im Anhang, die ich versuche, einzulesen.
Es handelt sich hier um ein ESRI-Shapefile, die Dokumentation zum Aufbau der Datei ist hier : http://www.esri.com/library/whitepap.../shapefile.pdf

Ich habe die Datei mit einem HexEditor durchleutet und durchgezählt, von der Datei her passt auch alles wie laut Dokumentation, beinhaltet eine PolyLinie mit 1 Part und 6 Points

Werte ich allerdings mein Objekt ShapeFile aus zur Laufzeit, dann sehe ich, dass die Variablen NumParts und NumPoints irgendwelche unnachvollziehbare hohe Werte enthalten - deswegen wird anscheinend mein Array dann überverhältnismäßig groß dimensioniert und es kommt zu einem Heap Overflow.

Hier die Auswertung:
<TSHAPEFILE> = {
<TOBJECT> = {
_vptr$TOBJECT = $592b1c},
FILEHEADER = {
FILECODE = 9994,
UNUSED1 = 0,
UNUSED2 = 0,
UNUSED3 = 0,
UNUSED4 = 0,
UNUSED5 = 0,
FILELEN = 126,
VERSION = 1000,
SHAPETYPE = 3,
XMIN = 10,
YMIN = 10,
XMAX = 172.48123448885769,
YMAX = 115.67794078524194,
ZMIN = 0,
ZMAX = 0,
MMIN = 0,
MMAX = 0},
RECORDHEADER = {
NUMMER = 9280,
LAENGE = 0},
PLHEAD = {
SHAPETYPE = 1076101120,
BOX = {
75,
20,
27.288444271758017,
66.00672307939206},
NUMPARTS = 411976715,
NUMPOINTS = 1079176168},
PLCONTENT = {
PARTS = $0,
POINTS = $0},
ERROR = false,
ERRMSG = $0,
PUNKTE = $0,
POLYLINIEN = $2baed0}

------------------
und hier der Quelltext meiner Unit (hatte gestern den Code nur ungefähr abgeschrieben):

Delphi-Quellcode:
unit shapefiles;

{$mode objfpc}{$H+}

interface

uses
  Classes, SysUtils;

type TSHPFileHeader = packed record
     // Big Endian
     FileCode : LongInt;
     Unused1,
     Unused2,
     Unused3,
     Unused4,
     Unused5 : LongInt;
     FileLen : LongInt;
     // Little Endian
     Version : LongInt;
     ShapeType: LongInt;
     Xmin : Double;
     Ymin : Double;
     Xmax : Double;
     Ymax : Double;
     Zmin : Double;
     Zmax : Double;
     Mmin : Double;
     Mmax : Double;
     end;

type TRecordHeader = packed record
                Nummer : LongInt; // Big Endian
                Laenge : LongInt; // Big Endian
                end;

type TBox = Array[0..3] of Double;

type TPunkt = packed record
     ID : LongInt;
     X : Double;
     Y : Double;
     end;

type TPunktXY = record
           X, Y : Double;
           end;

type TPolyLine = record
            ShapeType : LongInt;
            Box : TBox;
            NumParts : LongInt;
            NumPoints : LongInt;
            Parts : Array Of LongInt;
            Points : Array Of TPunktXY;
            end;

type TPolyHeader = packed record
            Shapetype : LongInt;
            Box : TBox;
            NumParts : LongInt;
            NumPoints : LongInt;
            end;
type TPolyContent = packed record
            Parts : Array of LongInt;
            Points : Array of TPunktXY;
            end;

type TShapefile = class
      public
       FileHeader : TSHPFileHeader;
       RecordHeader : TRecordHeader;
       PLHead : TPolyHeader;
       PLContent : TPolyContent;
       error : boolean;
       errmsg : String;

       Punkte : Array Of TPunkt;
       PolyLinien : Array of TPolyLine;

       constructor Create;
       procedure AddPoint (ID : LongInt; X, Y : Double);
       procedure AddPLPart (ID : LongInt; zahl : LongInt);
       procedure LoadSHP(datnam : string);
     end;

const shpNullShape = 0;
      shpPoint = 1;
      shpPolyLine = 3;
      shpPolygon = 5;
      shpMultiPoint = 8;
      shpPointZ = 11;
      shpPolyLineZ = 13;
      shpPolygonZ = 15;
      shpMultiPointZ = 18;
      shpPointM = 21;
      shpPolyLineM = 23;
      shpPolygonM = 25;
      shpMultiPointM = 28;
      shpMultiPatch = 31;

      sizeHeader = 100;


procedure SwapBytes(Var Bytes; Len : Integer);


implementation

constructor TShapeFile.Create;
begin
 inherited;
 error:=false;
 // Dynamische Arrays auf 0 setzen
 SetLength(Punkte,0);
 SetLength(PolyLinien,0);
end;


procedure TShapeFile.AddPoint(ID : LongInt; X, Y : Double);
begin
 SetLength(Punkte,Length(Punkte)+1);
 Punkte[High(Punkte)].ID:=ID;
 Punkte[High(Punkte)].X:=X;
 Punkte[High(Punkte)].Y:=Y;
end;

procedure TShapeFile.AddPLPart (ID : LongInt; zahl : LongInt);
begin
 //if (High(PolyLinien)<ID) then SetLength(PolyLinien,ID+1);
 //
end;

procedure TShapefile.LoadSHP(datnam : string);
var Strom : TFileStream;
    In_Punkt : TPunkt;
    index : integer;
    i,j : integer;

begin
// Lies den Header des Shapefiles ein
try
  Strom:=TFileStream.Create(datnam,fmOpenRead);
  Strom.ReadBuffer(FileHeader,SizeOf(FileHeader));
except
  error:=true;
  errmsg:='Kein gültiges ESRI-Shapefile!';
  Strom.Free;
  exit;
end;
// Big Endian in Little Endian umwandeln
SwapBytes(FileHeader.FileCode,SizeOf(FileHeader.FileCode));
SwapBytes(FileHeader.FileLen,SizeOf(FileHeader.FileLen));
// Records einlesen
index:=0;
try
  repeat
    index:=index+1;
    Strom.ReadBuffer(RecordHeader, SizeOf(RecordHeader)); // Big Endian
    SwapBytes(RecordHeader.Nummer, SizeOf(RecordHeader.Nummer));
    SwapBytes(RecordHeader.Laenge, SizeOf(RecordHeader.Laenge));
    case FileHeader.ShapeType of
         1 : begin // Punkt - Shapefile
             Strom.Read(In_Punkt,SizeOf(In_Punkt));
             AddPoint(RecordHeader.Nummer, In_Punkt.X, In_Punkt.Y);
             end;

         3 : begin // PolyLine - Shapefile
             SetLength(PolyLinien,index);
             Strom.ReadBuffer(PLHead,SizeOf(PLHead));
             SetLength(PLContent.Parts,PLHead.NumParts);
             SetLength(PLContent.Points,PLHead.NumPoints);
             Strom.ReadBuffer(PLContent,SizeOf(PLContent));
             end;
    end;

  until (Strom.Position>=((FileHeader.FileLen)*2)); // da Filesize in Word =
                                              // 16-Bit = 2 Bytes angegeben wird
except
  error:=true;
  errmsg:='Fehler beim Einlesen der einzelnen Elemente bei ID : '+IntToStr(RecordHeader.Nummer);
  Strom.Free;
  exit;
end;
Strom.Free;
end;

procedure SwapBytes(Var Bytes; Len : Integer); // Vertauscht die Byte-Order
Var swapped : PChar; // Usage : SwapBytes(i,sizeof(i));
    i : Integer;
begin
 GetMem(swapped, Len);
 try
   for i:=0 to Len-1 do
       swapped[Len-i-1]:=PChar(@Bytes)[i];
   Move(swapped^, Bytes, Len);
 finally
   FreeMem(swapped);
 end;
end;

end.
Angehängte Dateien
Dateityp: zip meineLangePolyLine.shp.zip (307 Bytes, 5x aufgerufen)

Geändert von lagalex (19. Feb 2013 um 11:12 Uhr)
  Mit Zitat antworten Zitat
lagalex

Registriert seit: 16. Jan 2011
7 Beiträge
 
#2

AW: Datei mit dynamischen Array einlesen

  Alt 19. Feb 2013, 09:38
RecordHeader.Nummer passt auch schon nicht sehe ich gerdae
  Mit Zitat antworten Zitat
Benutzerbild von lbccaleb
lbccaleb

Registriert seit: 25. Mai 2006
Ort: Rostock / Bremen
2.037 Beiträge
 
Delphi 7 Enterprise
 
#3

AW: Datei mit dynamischen Array einlesen

  Alt 19. Feb 2013, 11:01
Könntest du dir mal bitte angewöhnen, die Foren-Tags die dir hier zur verfügung gestellt werden, auch zu benutzen?
Das ist ja echt schrecklich, das kann doch keiner lesen.

(Du kannst auch nachträglich noch, deine Beiträge editieren)
Martin
MFG Caleb
TheSmallOne (MediaPlayer)
Die Dinge werden berechenbar, wenn man die Natur einer Sache durchschaut hat (Blade)
  Mit Zitat antworten Zitat
lagalex

Registriert seit: 16. Jan 2011
7 Beiträge
 
#4

AW: Datei mit dynamischen Array einlesen

  Alt 19. Feb 2013, 11:18
Danke für den Hinweis, bin neu im Forum und wusste noch nicht, dass das geht --- sieht doch gleich besser aus

Glaube in der Zwischenzeit, dass bei mir irgendwo was verschoben sein muss, die ersten 100 Byte Fileheader passen ja auch, dann wirds haarig:

ab Offset 100 steht in der Datei:
00 00 00 01 - ist Integer Big Endian, Wert sollte 1 sein da erster Record, danach kommt
00 00 00 48 - ebenfalls laut Doc Integer Big Endian, liefert die Größe des Records

dann
03 00 00 00 - Little Endian, soll den Wert 3 liefern

aber der erste Wert RecordHeader.Nummer stimmt schon nicht... Wer hat den Durchblick?
  Mit Zitat antworten Zitat
Benutzerbild von sx2008
sx2008

Registriert seit: 15. Feb 2008
Ort: Baden-Württemberg
2.332 Beiträge
 
Delphi 2007 Professional
 
#5

AW: Datei mit dynamischen Array einlesen

  Alt 19. Feb 2013, 12:16
Laut ESRI Doku sind manche Datenfelder Big Endian und andere sind Little Endian (Bytereihenfolge).
  Mit Zitat antworten Zitat
lagalex

Registriert seit: 16. Jan 2011
7 Beiträge
 
#6

AW: Datei mit dynamischen Array einlesen

  Alt 19. Feb 2013, 12:38
Ja das weiß ich, deswegen auch der Befehl SwapBytes für die BigEndians.
TStream.Position zeigt mir 100 bevor ich den ominösen RecordHeader einlese. Das was ich dann bekomme ist weder Big noch Little, hab alles probiert, mit und ohne SwapBytes.

Kann vielleicht der Fehler bei den Packed Records liegen?
Oder ist das in der Dokumentation beschriebene Integer evtl unsigned, habs aber auch mit LongWord und Cardinal probiert, keine Veränderung. Irgendwie steh ich auf der Leitung :-/

Geändert von lagalex (19. Feb 2013 um 12:44 Uhr)
  Mit Zitat antworten Zitat
lagalex

Registriert seit: 16. Jan 2011
7 Beiträge
 
#7

AW: Datei mit dynamischen Array einlesen

  Alt 19. Feb 2013, 13:29
Meine Güte! Ein typischer Fall von "Wald vor lauter Bäumen" nicht sehen...

es war das repeat .. until, hab wohl übers Ziel hinausgeschossen...

Dank an alle!!
  Mit Zitat antworten Zitat
Blup

Registriert seit: 7. Aug 2008
Ort: Brandenburg
1.487 Beiträge
 
Delphi 12 Athens
 
#8

AW: Datei mit dynamischen Array einlesen

  Alt 19. Feb 2013, 14:26
Nein, war es nicht. Das ist falsch:
Delphi-Quellcode:
SetLength(PLContent.Parts, PLHead.NumParts);
SetLength(PLContent.Points, PLHead.NumPoints);
Strom.ReadBuffer(PLContent,SizeOf(PLContent));
Und hier meine "verbesserte" Version:
Delphi-Quellcode:
unit shapefiles;

interface

uses
  Classes, SysUtils;

type
  TSHPFileHeader = packed record
    // Big Endian
    FileCode : LongInt;
    Unused1,
    Unused2,
    Unused3,
    Unused4,
    Unused5 : LongInt;
    FileLen : LongInt;
    // Little Endian
    Version : LongInt;
    ShapeType: LongInt;
    Xmin : Double;
    Ymin : Double;
    Xmax : Double;
    Ymax : Double;
    Zmin : Double;
    Zmax : Double;
    Mmin : Double;
    Mmax : Double;
  end;

  TRecordHeader = packed record
    Nummer: LongInt; // Big Endian
    Laenge: LongInt; // Big Endian
  end;

  TBox = Array[0..3] of Double;

  TPunkt = packed record
    ID : LongInt;
    X : Double;
    Y : Double;
  end;

  TPunktXY = record
    X, Y : Double;
  end;

  TPolyLine = record
    ShapeType : LongInt;
    Box : TBox;
    NumParts : LongInt;
    NumPoints : LongInt;
    Parts : Array Of LongInt;
    Points : Array Of TPunktXY;
  end;

  TPolyHeader = packed record
    Shapetype : LongInt;
    Box : TBox;
    NumParts : LongInt;
    NumPoints : LongInt;
  end;

  TPolyContent = packed record
    Parts : Array of LongInt;
    Points : Array of TPunktXY;
  end;

  TShapefile = class
  protected
    FErrMsg: string;
    FError : Boolean;
    procedure ReadFromStream(Stream : TFileStream);
  public
    FileHeader : TSHPFileHeader;
    PLHead : TPolyHeader;
    PLContent : TPolyContent;
    Punkte : array Of TPunkt;
    PolyLinien : array of TPolyLine;
    procedure AddPoint (ID : LongInt; X, Y : Double);
    procedure AddPLPart (ID : LongInt; zahl : LongInt);
    procedure LoadSHP(const AFilename : string);
    property ErrMsg: string read FErrMsg;
    property Error: Boolean read FError;
  end;

const
  shpNullShape = 0;
  shpPoint = 1;
  shpPolyLine = 3;
  shpPolygon = 5;
  shpMultiPoint = 8;
  shpPointZ = 11;
  shpPolyLineZ = 13;
  shpPolygonZ = 15;
  shpMultiPointZ = 18;
  shpPointM = 21;
  shpPolyLineM = 23;
  shpPolygonM = 25;
  shpMultiPointM = 28;
  shpMultiPatch = 31;

  sizeHeader = 100;

implementation

function ChangeEndian32(AValue: LongWord): LongWord; register;
asm
  bswap EAX // konvertiert Reienfolge der Byte
end;

procedure TShapeFile.AddPoint(ID: LongInt; X, Y: Double);
begin
 SetLength(Punkte,Length(Punkte)+1);
 Punkte[High(Punkte)].ID := ID;
 Punkte[High(Punkte)].X := X;
 Punkte[High(Punkte)].Y := Y;
end;

procedure TShapeFile.AddPLPart (ID : LongInt; zahl : LongInt);
begin
 //if (High(PolyLinien)<ID) then SetLength(PolyLinien,ID+1);
 //
end;

procedure TShapefile.ReadFromStream(Stream : TFileStream);
var
  In_Punkt : TPunkt;
  index : integer;
  RecordHeader : TRecordHeader;
begin
  FError := False;
  FErrmsg := '';
  // Lies den Header des Shapefiles ein
  try
    Stream.ReadBuffer(FileHeader,SizeOf(FileHeader));
  except
    FError := True;
    FErrmsg := 'Kein gültiges ESRI-Shapefile!';
    Exit;
  end;
  // Big Endian in Little Endian umwandeln
  FileHeader.FileCode := ChangeEndian32(FileHeader.FileCode);
  FileHeader.FileLen := ChangeEndian32(FileHeader.FileLen);
  // Records einlesen
  Index := 0;
  try
    repeat
      index:=index+1;
      Stream.ReadBuffer(RecordHeader, SizeOf(RecordHeader)); // Big Endian
      RecordHeader.Nummer := ChangeEndian32(RecordHeader.Nummer);
      RecordHeader.Laenge := ChangeEndian32(RecordHeader.Laenge);
      case FileHeader.ShapeType of
        1: // Punkt - Shapefile
          begin
            Stream.Read(In_Punkt, SizeOf(In_Punkt));
            AddPoint(RecordHeader.Nummer, In_Punkt.X, In_Punkt.Y);
          end;
        3: // PolyLine - Shapefile
          begin
            SetLength(PolyLinien, index);
            Stream.ReadBuffer(PLHead, SizeOf(PLHead));
            SetLength(PLContent.Parts, PLHead.NumParts);
            SetLength(PLContent.Points, PLHead.NumPoints);
            Stream.ReadBuffer(PLContent.Parts[0],
                              SizeOf(PLContent.Parts[0]) * PLHead.NumParts);
            Stream.ReadBuffer(PLContent.Points[0],
                              SizeOf(PLContent.Points[0]) * PLHead.NumPoints);
          end;
      end;
    until (Stream.Position >= (FileHeader.FileLen * 2)); // da Filesize in Word =
                                              // 16-Bit = 2 Bytes angegeben wird
  except
    FError := True;
    FErrmsg := 'Fehler beim Einlesen der einzelnen Elemente bei ID : ' + IntToStr(RecordHeader.Nummer);
    Exit;
  end;
end;

procedure TShapefile.LoadSHP(const AFilename : string);
var
  Stream : TFileStream;
begin
  Stream := TFileStream.Create(AFilename, fmOpenRead);
  try
    ReadFromStream(Stream);
  finally
    Stream.Free;
  end;
end;

end.
  Mit Zitat antworten Zitat
lagalex

Registriert seit: 16. Jan 2011
7 Beiträge
 
#9

AW: Datei mit dynamischen Array einlesen

  Alt 19. Feb 2013, 14:38
Hallo Blup,

Vielen Dank für Deine Antwort und Deine Mühe - ja, Deine ist wohl die elegantere Version als meine, werds mir genauer ansehen und dazulernen...

Ich habs jetzt so lösen können :

Delphi-Quellcode:
unit shapefiles;

{$mode objfpc}{$H+}

interface

uses
  Classes, SysUtils;

type TSHPFileHeader = packed record
     // Big Endian
     FileCode : LongInt;
     Unused1,
     Unused2,
     Unused3,
     Unused4,
     Unused5 : LongInt;
     FileLen : LongInt;
     // Little Endian
     Version : LongInt;
     ShapeType: LongInt;
     Xmin : Double;
     Ymin : Double;
     Xmax : Double;
     Ymax : Double;
     Zmin : Double;
     Zmax : Double;
     Mmin : Double;
     Mmax : Double;
     end;

type TRecordHeader = packed record
                Nummer : LongInt; // Big Endian
                Laenge : LongInt; // Big Endian
                end;

type TBox = Array[0..3] of Double;

type TPunkt = packed record
     ID : LongInt;
     X : Double;
     Y : Double;
     end;

type TPunktXY = record
           X, Y : Double;
           end;

type TPolyLine = record
            ShapeType : LongInt;
            Box : TBox;
            NumParts : LongInt;
            NumPoints : LongInt;
            Parts : Array Of LongInt;
            Points : Array Of TPunktXY;
            end;

type TPolyHeader = packed record
            Shapetype : LongInt;
            Box : TBox;
            NumParts : LongInt;
            NumPoints : LongInt;
            end;

type TPolyContent = packed record
            Parts : Array of LongInt;
            Points : Array of TPunktXY;
            end;

type TShapefile = class
      public
       FileHeader : TSHPFileHeader;
       RecordHeader : TRecordHeader;
       PLHead : TPolyHeader;
       PLContent : TPolyContent;
       error : boolean;
       errmsg : String;

       Punkte : Array Of TPunkt;
       PolyLinien : Array of TPolyLine;

       constructor Create;
       procedure AddPoint (ID : LongInt; X, Y : Double);
       procedure LoadSHP(datnam : string);
     end;

const shpNullShape = 0;
      shpPoint = 1;
      shpPolyLine = 3;
      shpPolygon = 5;
      shpMultiPoint = 8;
      shpPointZ = 11;
      shpPolyLineZ = 13;
      shpPolygonZ = 15;
      shpMultiPointZ = 18;
      shpPointM = 21;
      shpPolyLineM = 23;
      shpPolygonM = 25;
      shpMultiPointM = 28;
      shpMultiPatch = 31;

      sizeHeader = 100;

var wo : integer;

procedure SwapBytes(Var Bytes; Len : Integer);

implementation

constructor TShapeFile.Create;
begin
 inherited;
 error:=false;
 // Dynamische Arrays auf 0 setzen
 SetLength(Punkte,0);
 SetLength(PolyLinien,0);
end;

procedure TShapeFile.AddPoint(ID : LongInt; X, Y : Double);
begin
 SetLength(Punkte,Length(Punkte)+1);
 Punkte[High(Punkte)].ID:=ID;
 Punkte[High(Punkte)].X:=X;
 Punkte[High(Punkte)].Y:=Y;
end;

procedure TShapefile.LoadSHP(datnam : string);
var Strom : TFileStream;
    In_Punkt : TPunkt;
    index : integer;
    i,j : integer;

begin
// Lies den Header des Shapefiles ein
try
  Strom:=TFileStream.Create(datnam,fmOpenRead);
  Strom.ReadBuffer(FileHeader,SizeOf(FileHeader));
except
  error:=true;
  errmsg:='Kein gültiges ESRI-Shapefile!';
  Strom.Free;
  exit;
end;
// Big Endian in Little Endian umwandeln
SwapBytes(FileHeader.FileCode,SizeOf(FileHeader.FileCode));
SwapBytes(FileHeader.FileLen,SizeOf(FileHeader.FileLen));
// Records einlesen
index:=0;
try
  repeat
    index:=index+1;
    Strom.ReadBuffer(RecordHeader, 8); // Big Endian
    SwapBytes(RecordHeader.Nummer, 4);
    SwapBytes(RecordHeader.Laenge, 4);
    case FileHeader.ShapeType of
         1 : begin // Punkt - Shapefile
             Strom.Read(In_Punkt,SizeOf(In_Punkt));
             AddPoint(RecordHeader.Nummer, In_Punkt.X, In_Punkt.Y);
             end;

         3 : begin // PolyLine - Shapefile
             SetLength(PolyLinien,index);
             Strom.ReadBuffer(PLHead,SizeOf(PLHead));

             SetLength(PolyLinien,index);
             SetLength(PolyLinien[index-1].Parts,PLHead.NumParts);
             SetLength(PolyLinien[index-1].Points,PLHead.NumPoints);
             PolyLinien[index-1].ShapeType:=3;
             PolyLinien[index-1].Box:=PLHead.Box;
             PolyLinien[index-1].NumParts:=PLHead.NumParts;
             PolyLinien[index-1].NumPoints:=PLHead.NumPoints;

             for i:=0 to PLHead.NumParts-1 do
                 Strom.ReadBuffer(PolyLinien[index-1].Parts[i],SizeOf(PolyLinien[index-1].Parts[i]));
             for j:=0 to PLHead.NumPoints-1 do
                 Strom.ReadBuffer(PolyLinien[index-1].Points[j],SizeOf(PolyLinien[index-1].Points[j]));
             end;
    end;
  until (Strom.Position>=(FileHeader.FileLen*2)); // da Filesize in Word =
                                                    // 16-Bit = 2 Bytes angegeben wird
except
  error:=true;
  errmsg:='Fehler beim Einlesen der einzelnen Elemente bei ID : '+IntToStr(index);
  Strom.Free;
  exit;
end;
Strom.Free;
end;

procedure SwapBytes(Var Bytes; Len : Integer); // Vertauscht die Byte-Order
Var swapped : PChar; // Usage : SwapBytes(i,sizeof(i));
    i : Integer;
begin
 GetMem(swapped, Len);
 try
   for i:=0 to Len-1 do
       swapped[Len-i-1]:=PChar(@Bytes)[i];
   Move(swapped^, Bytes, Len);
 finally
   FreeMem(swapped);
 end;
end;

end.

Nochmals Vielen Dank an Alle!!
  Mit Zitat antworten Zitat
Benutzerbild von p80286
p80286

Registriert seit: 28. Apr 2008
Ort: Stolberg (Rhl)
6.659 Beiträge
 
FreePascal / Lazarus
 
#10

AW: Datei mit dynamischen Array einlesen

  Alt 19. Feb 2013, 12:30
Laut ESRI Doku sind manche Datenfelder Big Endian und andere sind Little Endian (Bytereihenfolge).
Na der Mischmasch ist ja vielleicht historisch gewachsen?
aber da sind sie ja nicht die einzigen.

@lagalex
Ich traue im allgemeinen nur dem Hexdump, den ich selber mache, darum Du bist Dir sicher, daß Du auch wirklich am Offset 100 startest?
Wenn da eine Verschiebung um 3 Byte stattgefunden hat, dann wäre das eine Erklärung für den Little/Big-Endian Wechsel.
(und Dokumentationspapier ist geduldig, sehr geduldig...)

Gruß
K-H
Programme gehorchen nicht Deinen Absichten sondern Deinen Anweisungen
R.E.D retired error detector
  Mit Zitat antworten Zitat
Antwort Antwort

 
Themen-Optionen Thema durchsuchen
Thema durchsuchen:

Erweiterte Suche
Ansicht

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 18:03 Uhr.
Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
LinkBacks Enabled by vBSEO © 2011, Crawlability, Inc.
Delphi-PRAXiS (c) 2002 - 2023 by Daniel R. Wolf, 2024-2025 by Thomas Breitkreuz