Autor Beitrag
Luzifer
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 98

WinXP Pro/ Vista
D5 Enterprise/D7 Enterprise/D2005 Architect
BeitragVerfasst: So 18.06.06 00:33 
HI leutz

ich hab nen kleines program geschrieben in dem ich einige objekte meiner eigenen klassen create

ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
var myobject: array of Tmyclass;
[...]
setlength(myobject,3)
for a:=0 to 2 do myobject[a]:=Tmyclass.create;
[...]
procedure TForm1.FormClose(Sender: TObject; var Action: TCloseAction);
var b:integer
begin
for b:=0 to 2 do myobject[b].free; // <== 
end;

ich glaube an der Stelle wo der Pfeil ist wird die Exception ausgelöst, aber ich weiß nicht wieso, oder hab ich irgendwo nen Fehler gemacht?
ich hab auch schon drüber nachgedacht ob es daran liegen könnte, dass Tmyclass eine Eigenschaft hat die ein array ist. Denn die Exception wird nur bei programbeendigung ausgelöst und auch nur wenn ich diese Eigenschaft aller myobjects verändert habe....

danke für eure hilfe im vorraus
PLuS
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 98

Win XP, Suse Linux 9.0
D5 Standard, D2005 Personal; Perl; PureBasic
BeitragVerfasst: So 18.06.06 01:39 
Ohne den Source deiner Klasse zu posten wird das wohl nichts! :P

_________________
Der letzte macht die Tür zu!
Luzifer Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 98

WinXP Pro/ Vista
D5 Enterprise/D7 Enterprise/D2005 Architect
BeitragVerfasst: So 18.06.06 13:22 
ich kopier einfach mal die komplette unit hier rein

ausblenden volle Höhe 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:
28:
29:
30:
31:
32:
33:
34:
35:
36:
37:
38:
39:
40:
41:
42:
43:
44:
45:
46:
47:
48:
49:
50:
51:
52:
53:
54:
55:
56:
57:
58:
59:
60:
61:
62:
63:
64:
65:
unit Umyclass;

interface
uses
  Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
  StdCtrls, ExtCtrls;

type
    Tmyclass=class
    private
    indexoberster, grosseoberster:integer;
    inhalt:array of integer;
    
    public                  
    markiert:boolean;
    constructor create(lange,nr:integer);
    property spitze:integer read grosseoberster;
    property hohe:integer read indexoberster;
    function getinhalt(d:integer):integer;
    function itemabgeben:integer;
    procedure itemaufnehmen(grosse:integer);
    property stapel[d:integer]:integer read getinhalt;
    end;

implementation

function Tmyclass.getinhalt(d:integer):integer;
begin
  result:=inhalt[d];
end;

function Tmyclass.itemabgeben:integer;
var grosse:integer;
begin
grosse:=grosseoberster;
grosseoberster:=inhalt[indexoberster-1];
inhalt[indexoberster]:=0;
indexoberster:=indexoberster-1;
result:=grosse;
end;

procedure Tmyclass.itemaufnehmen(grosse:integer);
begin
inhalt[indexoberster+1]:=grosse;
indexoberster:=indexoberster+1;
grosseoberster:=inhalt[indexoberster];
end;

constructor Tmyclass.create(lange,nr:integer);
var i:integer;
begin
setlength(inhalt,lange);
  for i:=1 to lange do begin
    if nr=0 then inhalt[i]:=(lange+1)-i else inhalt[i]:=0;
  end;
if nr=0 then begin
indexoberster:=lange;
grosseoberster:=1;
end else begin
indexoberster:=0;
grosseoberster:=0;
end;
end;

end.


wie ihr sicherlich seht wird die Eigenschaft "inhalt" der 1. Intanz von Myclass standartmäßig im Constructor "gefüllt", die anderen "geleert"
BenBE
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 8721
Erhaltene Danke: 191

Win95, Win98SE, Win2K, WinXP
D1S, D3S, D4S, D5E, D6E, D7E, D9PE, D10E, D12P, DXEP, L0.9\FPC2.0
BeitragVerfasst: So 18.06.06 13:33 
Dynamische Arrays in Delphi sind immer 0-basiert ... Also von 0 bis Length(Array) - 1 ...

_________________
Anyone who is capable of being elected president should on no account be allowed to do the job.
Ich code EdgeMonkey - In dubio pro Setting.
Luzifer Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 98

WinXP Pro/ Vista
D5 Enterprise/D7 Enterprise/D2005 Architect
BeitragVerfasst: So 18.06.06 13:37 
user profile iconBenBE hat folgendes geschrieben:
Dynamische Arrays in Delphi sind immer 0-basiert ... Also von 0 bis Length(Array) - 1 ...


ja, ich weiß jetzt ehrlich gesagt nicht was du mir damit sagen willst. hab ich das irgendwo falsch gemacht? oder bezieht sich das auf meinen satz vom vorherigen post, wo ich von der 1. Instanz gesprochen habe? das bezog sich schon auf die mit dem Index 0. ich bin ein wenig verwirrt....
Born-to-Frag
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 1094

Win XP SP2, Win 2000 SP4
Delphi 7, 2k5
BeitragVerfasst: So 18.06.06 13:41 
nicht von 1 bis lange sondern von 0 bis lange - 1 ;)

greetz

_________________
Theorie ist wenn man alles weiß, aber nichts funktioniert. Praxis ist wenn alles funktioniert, aber niemand weiß warum.
Microsoft vereint Theorie und Praxis: Nichts funktioniert und niemand weiß warum.
BenBE
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 8721
Erhaltene Danke: 191

Win95, Win98SE, Win2K, WinXP
D1S, D3S, D4S, D5E, D6E, D7E, D9PE, D10E, D12P, DXEP, L0.9\FPC2.0
BeitragVerfasst: So 18.06.06 13:41 
user profile iconLuzifer hat folgendes geschrieben:
user profile iconBenBE hat folgendes geschrieben:
Dynamische Arrays in Delphi sind immer 0-basiert ... Also von 0 bis Length(Array) - 1 ...


ja, ich weiß jetzt ehrlich gesagt nicht was du mir damit sagen willst. hab ich das irgendwo falsch gemacht? oder bezieht sich das auf meinen satz vom vorherigen post, wo ich von der 1. Instanz gesprochen habe? das bezog sich schon auf die mit dem Index 0. ich bin ein wenig verwirrt....


Nope ;-) Bezieht sich auf den Konstrutor deiner Klassen:

ausblenden Delphi-Quelltext
 
49:
50:
51:
52:
53:
54:
55:
56:
57:
58:
59:
60:
61:
62:
63:
{ ... }
constructor Tmyclass.create(lange,nr:integer);
var i:integer;
begin
setlength(inhalt,lange);
  for i:=1 to lange do begin
    if nr=0 then inhalt[i]:=(lange+1)-i else inhalt[i]:=0;
  end;
if nr=0 then begin
indexoberster:=lange;
grosseoberster:=1;
end else begin
indexoberster:=0;
grosseoberster:=0;
end;
end;

_________________
Anyone who is capable of being elected president should on no account be allowed to do the job.
Ich code EdgeMonkey - In dubio pro Setting.
alias5000
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 2145

WinXP Prof SP2, Ubuntu 9.04
C/C++(Code::Blocks, VS.NET),A51(Keil),Object Pascal(D2005PE, Turbo Delphi Explorer) C# (VS 2008 Express)
BeitragVerfasst: So 18.06.06 13:42 
ER wird das hier meinen
user profile iconLuzifer hat folgendes geschrieben:
ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
constructor Tmyclass.create(lange,nr:integer);
var i:integer;
begin
setlength(inhalt,lange);
  for i:=1 to lange do begin
    if nr=0 then inhalt[i]:=(lange+1)-i else inhalt[i]:=0;
  end;

if nr=0 then begin
indexoberster:=lange;
grosseoberster:=1;
end else begin
indexoberster:=0;
grosseoberster:=0;
end;
end;

end.

_________________
Programmers never die, they just GOSUB without RETURN
Luzifer Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 98

WinXP Pro/ Vista
D5 Enterprise/D7 Enterprise/D2005 Architect
BeitragVerfasst: So 18.06.06 13:43 
ahso! alles klar, aber meinst du dass das den Fehler (die Exception) auslöst?
Born-to-Frag
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 1094

Win XP SP2, Win 2000 SP4
Delphi 7, 2k5
BeitragVerfasst: So 18.06.06 13:46 
ja, probier es doch einfach aus!

_________________
Theorie ist wenn man alles weiß, aber nichts funktioniert. Praxis ist wenn alles funktioniert, aber niemand weiß warum.
Microsoft vereint Theorie und Praxis: Nichts funktioniert und niemand weiß warum.
BenBE
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 8721
Erhaltene Danke: 191

Win95, Win98SE, Win2K, WinXP
D1S, D3S, D4S, D5E, D6E, D7E, D9PE, D10E, D12P, DXEP, L0.9\FPC2.0
BeitragVerfasst: So 18.06.06 13:48 
Deine ganze Klasse arbeitet mit den falschen Indizes ... z.B. ItemAufnehmen ... Dor greifst Du garantiert auf ein nicht existierendes Element zu ... Außerdem fehlt dort das SetLength, ...

Schau Dir am besten in der DOH (Delphi Online Hilfe) mal dan Abschnitt zu dynamischen Artrays an. Ich denke, der sollte Dir ein wenig bei deinem Problem helfen ...

_________________
Anyone who is capable of being elected president should on no account be allowed to do the job.
Ich code EdgeMonkey - In dubio pro Setting.
alias5000
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 2145

WinXP Prof SP2, Ubuntu 9.04
C/C++(Code::Blocks, VS.NET),A51(Keil),Object Pascal(D2005PE, Turbo Delphi Explorer) C# (VS 2008 Express)
BeitragVerfasst: So 18.06.06 13:49 
du bekommst es ja von Delphi angezeigt, wo es knallt, und wenns nicht genug infos sind, kannst du dich mit Breakpoints und F7/F8 durch den Code hangeln

Gruß alias5000

_________________
Programmers never die, they just GOSUB without RETURN
Luzifer Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 98

WinXP Pro/ Vista
D5 Enterprise/D7 Enterprise/D2005 Architect
BeitragVerfasst: So 18.06.06 14:06 
der Fehler ist so einfach, und ich bin so blöd =)

ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
setlength(inhalt,lange+1); //das muss hier natürlich ne length von lange+1 haben, denn...

  for i:=1 to lange do begin  //hier gehe ich ja schon bis zum Index lange+1
    if nr=0 then inhalt[i]:=(lange+1)-i else inhalt[i]:=0; 
  end;
BenBE
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 8721
Erhaltene Danke: 191

Win95, Win98SE, Win2K, WinXP
D1S, D3S, D4S, D5E, D6E, D7E, D9PE, D10E, D12P, DXEP, L0.9\FPC2.0
BeitragVerfasst: So 18.06.06 14:14 
Das behebt zwar ein Symptom, aber nicht die Krankheit, an der dein Source leidet ...

_________________
Anyone who is capable of being elected president should on no account be allowed to do the job.
Ich code EdgeMonkey - In dubio pro Setting.
Luzifer Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 98

WinXP Pro/ Vista
D5 Enterprise/D7 Enterprise/D2005 Architect
BeitragVerfasst: So 18.06.06 14:22 
du meinst also ich sollte alles so umstellen, dass es bei Index 0 beginnt?
alias5000
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 2145

WinXP Prof SP2, Ubuntu 9.04
C/C++(Code::Blocks, VS.NET),A51(Keil),Object Pascal(D2005PE, Turbo Delphi Explorer) C# (VS 2008 Express)
BeitragVerfasst: So 18.06.06 14:26 
*nick*

_________________
Programmers never die, they just GOSUB without RETURN