Autor Beitrag
Tigerandy
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 21



BeitragVerfasst: Mi 11.10.06 11:01 
Hallo,

ich habe folgenden Record:

ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
type
  TAuftrag = record
    ID : integer;
    Bez : string;
    Mat : real;
    Lohn : real;
    Pic : TImage;
  end;
var
  Auftr: array of TAuftrag;
  pic: TImage;


Warum ergibt dann folgender Code eine Zugriffsverletzung und wie kann ich diese umgehen? Einem "normalen" TImage kann ich doch auch nil zuweisen (TImage.Picture:=nil)

ausblenden Delphi-Quelltext
1:
2:
3:
4:
setlength(Auftr,1);
pic.Picture:=nil;            // <---- funktioniert
Auftr[0].Pic.Picture:=nil;   // <---- funktioniert nicht
Auftr[0].Pic:=pic;           // <---- funktioniert auch nicht


Was mache ich falsch? Würde mich sehr freuen, wenn mir jemand helfen könnte.

Gruß
Tiger
Narses
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Administrator
Beiträge: 10185
Erhaltene Danke: 1261

W11x64
TP3 .. D7pro .. D10.2CE
BeitragVerfasst: Mi 11.10.06 11:04 
Moin!

Du hast doch noch gar keine Instanz von TImage im record angelegt. ;)

Abgesehen davon, warum TImage? Meinst du nicht eher TBitmap? :gruebel:

cu
Narses

_________________
There are 10 types of people - those who understand binary and those who don´t.
Tigerandy Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 21



BeitragVerfasst: Mi 11.10.06 11:12 
Hallo,

das Zuweisen von Bildern (ob jetzt Bitmaps oder JPGs oder ähnliches - möchte da flexibel bleiben, deshalb TImage) funktioniert ja - nur wenns darum geht, den Inhalt wieder auf "nil" zu setzen (so wie am Anfang, als noch kein Bild zugewiesen war), dann kommt eben diese Zugriffsverletzung.

Gruß
Tiger
Narses
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Administrator
Beiträge: 10185
Erhaltene Danke: 1261

W11x64
TP3 .. D7pro .. D10.2CE
BeitragVerfasst: Mi 11.10.06 11:15 
Moin!

Ja, klar kommt da eine Zugriffsverletzung, du greifst ja auch auf Eigenschaften eines nicht initialisierten Objekts zu. ;) Noch nicht gesehen? :D

cu
Narses

_________________
There are 10 types of people - those who understand binary and those who don´t.
Tigerandy Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 21



BeitragVerfasst: Mi 11.10.06 11:19 
Entweder steh ich jetzt auf dem Schlauch, oder was meinst Du? Muss ich an der Record-Definition was ändern?
Narses
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Administrator
Beiträge: 10185
Erhaltene Danke: 1261

W11x64
TP3 .. D7pro .. D10.2CE
BeitragVerfasst: Mi 11.10.06 11:25 
Moin!

ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
type
  TAuftrag = record
    ID : integer;
    Bez : string;
    Mat : real;
    Lohn : real;
    Pic : TPicture; // warum TImage (=Control), TPicture reicht doch
  end;

var
  Auftr: array of TAuftrag;

SetLength(Auftr,1);
Auftr[0].Pic := TPicture.Create;

cu
Narses

_________________
There are 10 types of people - those who understand binary and those who don´t.
Tigerandy Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 21



BeitragVerfasst: Mi 11.10.06 11:30 
Alles klar - danke!!

Hab da wohl TPicture und TImage verwechselt... ;)

Gruß
Tiger
Narses
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Administrator
Beiträge: 10185
Erhaltene Danke: 1261

W11x64
TP3 .. D7pro .. D10.2CE
BeitragVerfasst: Mi 11.10.06 11:41 
Moin!

Markierst du den Thread noch entsprechend, wenn dein Problem gelöst ist? Danke. ;)

cu
Narses

_________________
There are 10 types of people - those who understand binary and those who don´t.
Tigerandy Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 21



BeitragVerfasst: Mi 11.10.06 11:42 
So weit so gut, aber mit TPicture und TPicture.Create leider gleiche Zugriffsverletzung beim Aufruf von Auftr[0].Pic:=nil; wie vorher... :(
Narses
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Administrator
Beiträge: 10185
Erhaltene Danke: 1261

W11x64
TP3 .. D7pro .. D10.2CE
BeitragVerfasst: Mi 11.10.06 11:59 
Moin!

Was machst du denn da immer mit dem := NIL... :gruebel:

Das ist doch ein dynamisches Objekt, wie wäre es denn mit Freigeben? ;)
ausblenden Delphi-Quelltext
1:
2:
3:
4:
SetLength(Auftr,1);  
Auftr[0].Pic := TPicture.Create;
// Dinge damit tun
FreeAndNil(Auftr[0].Pic);

cu
Narses

_________________
There are 10 types of people - those who understand binary and those who don´t.
Tigerandy Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 21



BeitragVerfasst: Mi 11.10.06 12:18 
Ich muss halt ein Bild zuweisen und auch wieder löschen können. Und das Löschen habe ich halt immer mit :=nil gemacht. Aber freigeben und neu initialisieren ist natürlich auch eine gute Lösung, da nach der Initialisierung die Variable sowieso auf nil steht.

Vielen Dank!

Gruß
Tiger