| Autor |
Beitrag |
sourcehunter
      
Beiträge: 482
Win XP | Suse 10.1
Delphi 2005 Pers.
|
Verfasst: Fr 08.10.04 18:21
Ich habe folgende Prozedur geschrieben:
1: 2: 3: 4: 5: 6: 7: 8: 9: 10: 11: 12: 13: 14: 15: 16: 17: 18: 19: 20: 21: 22: 23: 24: 25: 26: 27: 28: 29: 30: 31: 32: 33: 34: 35: 36: 37: 38: 39: 40: 41: 42: 43: 44: 45: 46: 47: 48: 49: 50:
| procedure TOpenGLObjekt.SaveToFile(filename:String); var data:File; floatsize:Byte; intsize:Byte; numints:Array[0..1] of Byte; numfloats:Array[0..1] of Byte; numintsi,numfloatsi:Integer; bufbyte:Byte; i,j:Integer; bufint:GLint; buffloat:GLfloat; bytes:Array of Byte; begin floatsize:=SizeOf(GLfloat); intsize:=SizeOf(GLint); numintsi:=Length(ints); numints[0]:=numintsi and $FF; numints[1]:=(numintsi SHR 8) and $FF; numfloatsi:=Length(floats); numfloats[0]:=numfloatsi and $FF; numfloats[1]:=(numfloatsi SHR 8) and $FF; AssignFile(data,filename); Rewrite(data,1); BlockWrite(data,intsize,1); BlockWrite(data,floatsize,1); BlockWrite(data,numints[0],1); BlockWrite(data,numints[1],1); BlockWrite(data,numfloats[0],1); BlockWrite(data,numfloats[1],1); for i:=0 to numintsi-1 do begin bufint:=ints[i]; for j:=0 to intsize-1 do begin bufbyte:=bufint and $FF; bufint:=bufint SHR 8; BlockWrite(data,bufbyte,1); end; end; for i:=0 to numfloatsi-1 do begin buffloat:=floats[i]; bytes:=Pointer(@buffloat); for j:=0 to floatsize-1 do begin BlockWrite(data,bytes[j],1); end; end; CloseFile(data); end; |
Kann mir bitte jemand erklären, warum er beim CloseFile eine ungültige Zeigeroperation hat?
_________________ Linux und OpenSource rulez!
|
|
raziel
      
Beiträge: 2453
Arch Linux
JS (WebStorm), C#, C++/CLI, C++ (VS2013)
|
Verfasst: Fr 08.10.04 19:05
Also entweder liegts daran, dass die Datei gar nicht geöffnet wurde oder an den Variablen ints und/oder floats, die ja dyn. Arrays zu sein scheinen. Ersteres kannst Du mit {$I+}, IOResult und {$I-} überprüfen, zweiteres am besten mal posten, weils mit den Dummys, die ich eingefügt habe, super funktioniert.
_________________ JSXGraph
|
|
sourcehunter 
      
Beiträge: 482
Win XP | Suse 10.1
Delphi 2005 Pers.
|
Verfasst: Fr 08.10.04 19:31
Die Klasse hat folgenden Aufbau:
Delphi-Quelltext 1: 2: 3: 4: 5: 6: 7: 8: 9: 10: 11: 12: 13:
| TOpenGLObjekt=class private ints:Array of GLInt; floats:Array of GLfloat; public constructor Create; destructor Destroy; override; procedure LoadFromFile(filename:String); procedure Draw; procedure Show(dest:TStrings); procedure SaveToFile(filename:String); procedure Test1; end; |
Vor der Speichern-Funktion habe ich die Funktion Test1 aufgerufen, die wie folgt aussieht:
1: 2: 3: 4: 5: 6: 7: 8: 9: 10: 11: 12: 13: 14: 15: 16: 17: 18: 19: 20: 21: 22: 23: 24: 25: 26: 27: 28: 29: 30: 31: 32: 33: 34: 35: 36: 37: 38: 39: 40:
| procedure TOpenGLObjekt.Test1; begin SetLength(ints,11); ints[0]:=0; ints[1]:=8; ints[2]:=8; ints[3]:=29; ints[4]:=8; ints[5]:=29; ints[6]:=8; ints[7]:=29; ints[8]:=8; ints[9]:=29; ints[10]:=1; SetLength(floats,24); floats[0]:=1.0; floats[1]:=0.0; floats[2]:=0.0; floats[3]:=-1.0; floats[4]:=1.0; floats[5]:=0.0; floats[6]:=0.0; floats[7]:=1.0; floats[8]:=0.0; floats[9]:=-1.0; floats[10]:=-1.0; floats[11]:=0.0; floats[12]:=0.0; floats[13]:=0.0; floats[14]:=1.0; floats[15]:=1.0; floats[16]:=-1.0; floats[17]:=0.0; floats[18]:=1.0; floats[19]:=1.0; floats[20]:=1.0; floats[21]:=1.0; floats[22]:=1.0; floats[23]:=0.0; end; |
Nochwas: Angenommen die Datei würde nicht geöffnet werden, könnte ich dann BlockWrite ausführen?
_________________ Linux und OpenSource rulez!
|
|
sourcehunter 
      
Beiträge: 482
Win XP | Suse 10.1
Delphi 2005 Pers.
|
Verfasst: Fr 08.10.04 20:27
Danke für deine Hilfe raziel. Ich habe inzwischen eine Eingebung gehabt und das Problem wie folgt gelöst:
Delphi-Quelltext 1: 2: 3: 4: 5: 6: 7: 8: 9: 10: 11: 12: 13: 14: 15: 16: 17: 18: 19: 20: 21: 22: 23: 24: 25: 26: 27:
| procedure TOpenGLObjekt.SaveToFile(filename:String); var data:File; floatsize:Byte; intsize:Byte; numintsi,numfloatsi:Integer; i:Integer; begin floatsize:=SizeOf(GLfloat); intsize:=SizeOf(GLint); numintsi:=Length(ints); numfloatsi:=Length(floats); AssignFile(data,filename); Rewrite(data,1); BlockWrite(data,intsize,1); BlockWrite(data,floatsize,1); BlockWrite(data,numintsi,SizeOf(numintsi)); BlockWrite(data,numfloatsi,SizeOf(numfloatsi)); for i:=0 to numintsi-1 do begin BlockWrite(data,ints[i],intsize); end; for i:=0 to numfloatsi-1 do begin BlockWrite(data,floats[i],floatsize); end; CloseFile(data); end; |
_________________ Linux und OpenSource rulez!
|
|
|