Autor Beitrag
VD
Hält's aus hier
Beiträge: 8



BeitragVerfasst: Mo 09.08.04 18:51 
moin,

ich hab eine Klasse TTexObject, davon ein array

ausblenden Delphi-Quelltext
1:
2:
TTexArray = array of TTexObject;
PTexArray = ^TTexArray;


jetzt liefert:

ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
var Texture : TTexObject;
    a : PTexArray;
begin
        getmem( a, 4 );
        texture := TTexobject.create;
        a^[ 0 ] := texture;
        freemem( a );
end;


eine zugriffsverletzung, und zwar genau dann wenn ich in das array was reingeschrieben hab und dann versuch den speicher freizugeben
ohne reinschreiben funzt das freigeben

frage, wie bekomm ich das problem weg, also den speicher freigegeben wenn ich das array nimmer brauch?

schonmal dank für jede hilfe :)

VD


Moderiert von user profile iconChristian S.: Code- durch Delphi-Tags ersetzt.
raziel
ontopic starontopic starontopic starontopic starontopic starontopic starofftopic starofftopic star
Beiträge: 2453

Arch Linux
JS (WebStorm), C#, C++/CLI, C++ (VS2013)
BeitragVerfasst: Mo 09.08.04 18:57 
Für den Pointer brauchst Du doch kein Speicher reservieren... :roll:
Du hast für das Array noch keinen Speicher reserviert:
ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
var Texture : TTexObject;
  a : PTexArray;
begin
  texture := TTexobject.create;
  SetLength(a^, 1);
  a^[ 0 ] := texture;
end;

_________________
JSXGraph
UC-Chewie
ontopic starontopic starontopic starontopic starontopic starontopic starofftopic starofftopic star
Beiträge: 531

WinXP
D5 Ent
BeitragVerfasst: Mo 09.08.04 19:15 
Ein dyn. Array ist bereits ein Zeiger! Deshalb erstell direkt eine Variable vom Typ deines Array-Typen.

_________________
Egal wie dumm man selbst ist, es gibt immer andere, die noch dümmer sind