Autor Beitrag
Sylvus
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 195



BeitragVerfasst: Do 03.12.09 20:43 
So, mir reicht es, ist zwar ne ganz dumme Frage, aber ich komm nicht weiter.
Immer wenn ich mein Programm beende kommt folgende Meldung:

Erste Gelegenheit für Exception bei $7C812AEB. Exception-Klasse EAccessViolation mit Meldung 'Zugriffsverletzung bei Adresse 0046FCDF in Modul 'Project1.exe'. Lesen von Adresse 00000008'. Prozess Project1.exe (1112)

Das ganze liegt wohl an diesem Code:
ausblenden 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:
 var
 IUrls:array of TImage;

implementation
uses Unit1;

var
AUrls:array[0..5] of string;


procedure Ini;
var
I:integer;
begin
AUrls[0]:='test';
...

Setlength(IUrls,length(AUrls)-1);
for I:=0 to length(AUrls)-1 do begin
    IUrls[I]:=TImage.Create(Form1);
    IUrls[I].Parent := Form1.PShowW;
...
    IUrls[I].Name:='IW'+AUrls[I];
end;

Ich erzeuge die Bilder und dachte bisher, dass ich sie damit wieder freigebe:
ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
procedure TForm1.FormClose(Sender: TObject; var Action: TCloseAction);
var
    I: integer;
begin
    for I := 0 to length(IUrls) -1 do
    begin
        freeandnil(IUrls[I]);
    end;
end;

Scheint aber alles nicht so zu klappen, vielleicht könnt ihr mir ja sagen, was da falsch ist :)
Danke
Sylvus
Andreas L.
ontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic starofftopic star
Beiträge: 1703
Erhaltene Danke: 25

Windows Vista / Windows 10
Delphi 2009 Pro (JVCL, DragDrop, rmKlever, ICS, EmbeddedWB, DEC, Indy)
BeitragVerfasst: Do 03.12.09 20:54 
Versuchs mal so:
ausblenden Delphi-Quelltext
1:
2:
  for i := Length(IUrls) -1 downto 0 do
    IUrls[i].Free;
Sylvus Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 195



BeitragVerfasst: Do 03.12.09 21:00 
Nein leider nicht:
Erste Gelegenheit für Exception bei $7C812AEB. Exception-Klasse EAccessViolation mit Meldung 'Zugriffsverletzung bei Adresse 0046FCDF in Modul 'Project1.exe'. Lesen von Adresse 00000008'. Prozess Project1.exe (5364)

auch wenn ich FreeAndNil benutzte. Sonst noch Ideen?

Grüße
Gausi
ontopic starontopic starontopic starontopic starontopic starontopic starofftopic starofftopic star
Beiträge: 8554
Erhaltene Danke: 481

Windows 7, Windows 10
D7 PE, Delphi XE3 Prof, Delphi 10.3 CE
BeitragVerfasst: Do 03.12.09 21:15 
Soweit ich weiß, musst du die Images gar nicht selbst freigeben, bzw. ist es sogar an dieser Stelle falsch, denn
ausblenden Delphi-Quelltext
1:
IUrls[I]:=TImage.Create(Form1);					

Hier erstellst du die Images und gibst als Owner die Form1 an. Damit ist Form1 dann für das Freigeben der Images verantwortlich.
Die Fehlermeldung kommt, da das FormDestroy die Images freigeben will, die du schon vorher zerstört hast.

Wenn du das Freigeben selber machen willst, dann solltest du als Parameter beim Create Nil übergeben.

_________________
We are, we were and will not be.
Sylvus Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 195



BeitragVerfasst: Do 03.12.09 21:20 
habs jetzt einmal mit nil gemacht und einmal ganz raus genommen, Fehler bleibt aber.....
Kann ich irgendeinen dummen Fehler gemacht haben?

Grüße Sylvus
Narses
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Administrator
Beiträge: 10185
Erhaltene Danke: 1261

W11x64
TP3 .. D7pro .. D10.2CE
BeitragVerfasst: Do 03.12.09 21:30 
Moin!

Deine Arrays sind nicht synchron:
ausblenden 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:
var
  IUrls:array of TImage;

var
  AUrls:array[0..5] of string;

procedure Ini;
  var
    I:integer;
begin
  AUrls[0]:='test';
  ...

  Setlength(IUrls,Length(AUrls)); // nicht -1, sonst fehlt einer!
  for I := 0 to High(IUrls) do begin // das Array nehmen, um das es geht!
    IUrls[I]:=TImage.Create(NIL); // wenn du selbst freigibst, NIL!
    IUrls[I].Parent := Form1.PShowW;
    ...
    IUrls[I].Name:='IW'+AUrls[I];
  end;

procedure TForm1.FormClose(Sender: TObject; var Action: TCloseAction);
  var
    I: integer;
begin
    for I := 0 to High(IUrls) do
      IUrls[I].Free;
cu
Narses

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



BeitragVerfasst: Do 03.12.09 22:40 
danke! Funktioniert, ja dann war die -1 wohl falsch :)

DANKE
bis bald
ffgorcky
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 573

WIN XP/2000 & 7Prof (Familie:Win95,Win98)

BeitragVerfasst: Mi 09.12.09 20:38 
Ja, das muss doch auch so sein, dass die beiden Arrays gleich lang sind.
Deine Anweisung
ausblenden Delphi-Quelltext
1:
Setlength(IUrls,length(AUrls)-1);					

würde ja das Array IUrls eine Stelle kürzer machen, als das Array AUrls