Autor Beitrag
DarkHunter
ontopic starontopic starontopic starontopic starontopic starontopic starofftopic starofftopic star
Beiträge: 477

Win XP
D3 Prof, D2005 PE
BeitragVerfasst: So 10.04.05 20:59 
Hallo

ich habe ein kleines Problem
Ich habe ein Karte(Timage),

Beim Klick wird die Koordinate errechnet, von dem Feld in das geklickt wurde.

Jetzt das Problem
egal wohin ich Klicke kommt immer der Fehler:
ausblenden Quelltext
1:
Zugriffsverletzung bei Addresse 00404504 in Modul AoR.exe. Lesen von Addresse 357C3564.					


Der betreffende Source sieht so aus:
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:
28:
procedure tform1.info(x,y:integer);
var what: string;
werte: Tstringlist;
begin
werte := Tstringlist.Create;

what := koordinate[x,y];
if what = '' then what := 'leer';
werte.LoadFromFile('daten\gebaeude\'+what+'.txt');
img_info.picture.loadfromfile('daten\gebaeude\'+what+'.bmp');
pnl_info_name.caption := werte.strings[0];

pnl_info_kosten_holz.caption := werte.strings[1];
pnl_info_kosten_stein.caption := werte.strings[2];
pnl_info_kosten_lehm.caption := werte.strings[3];

pnl_info_prod_1.caption := werte.strings[2];
pnl_info_prod_2.caption := werte.strings[2];
pnl_info_prod_3.caption := werte.strings[2];
gb_info_prod_1.caption := ressourcename[strtoint(werte.strings[2])];
gb_info_prod_2.caption := ressourcename[strtoint(werte.strings[2])];
gb_info_prod_3.caption := ressourcename[strtoint(werte.strings[2])];

gb_info_ben_1.caption := ressourcename[strtoint(werte.strings[2])];
pnl_info_ben_1.caption := werte.strings[2];
gb_info_ben_2.caption := ressourcename[strtoint(werte.strings[2])];
pnl_info_ben_2.caption := werte.strings[2];
end;

die procedure soll einige Felder mit Informationen über das "Feld" liefern in das Geklickt wurde


Die procedure zum errechnen der Koordinate so:
ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
procedure Tform1.wherecursor;
begin
curposx := mouse.CursorPos.X - form1.left - 8;
curposy := mouse.CursorPos.Y -form1.top - 16;
wox := curposx div laenge;
wox := wox * laenge;
woy := curposy div hoehe;
woy := woy * hoehe;
koordx := curposx div laenge;
koordy := curposy div hoehe;
end;

(Ich weiß ist nicht ganz OOP-Konform[Globale Vars], will ich noch ändern, aber momentan weiß icht nicht wie :D)
DarkHunter Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starofftopic starofftopic star
Beiträge: 477

Win XP
D3 Prof, D2005 PE
BeitragVerfasst: Di 12.04.05 20:24 
Kann mir niemand helfen :?:

_________________
I believe that every human has a finite number of heart-beats. I don't intend to waste any of mine running around doing exercises.
- Neil Armstrong
Muetze1
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 346



BeitragVerfasst: Di 12.04.05 20:57 
Moin!

Schonmal debuggt und dem Click nachgegangen bis wo er auf die ungültige Instanz/Adresse zugreift? Du kannst mit den kompletten Quellen und dem Debugger viel mehr vor Ort ausrichten als wir hier mit unseren Glaskugeln...

MfG
Muetze1
Radioactive
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 179

Win 98, Win XP Home SP2
D3 Prof, D7 Pers, D2005 Pers
BeitragVerfasst: Di 12.04.05 21:00 
user profile iconDarkHunter hat folgendes geschrieben:

ausblenden Delphi-Quelltext
1:
pnl_info_name.caption := werte.strings[0];					


Vermutlich tritt der Fehler an dieser Stelle auf. Ich bin mir jetzt nicht sicher, aber gibt es gibt doch xyz.Strings[0] gar nicht.
Meistens ist der Grund einer der Anweisungen mit den Eckigen Klammern danach.

Bitte sag uns doch mal, bei welcher Zeile der Fehler auftritt (zum Beispiel mit F7 die ganze Funktion durchgehen).

_________________
Radioactive
"Wer scrollt, verliert!" Matthias Stein, Informatiklehrer am GG
DarkHunter Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starofftopic starofftopic star
Beiträge: 477

Win XP
D3 Prof, D2005 PE
BeitragVerfasst: Di 12.04.05 22:13 
ausblenden Delphi-Quelltext
1:
 stringlist.strings[0]					

gibt es
es ist die erste der liste
Die Zählung beginnt bei null und nciht bei eins

So
wo ist der Fehler:
der Fehler tritt in der Zeile 7 der funktion auf,

hm muss ich evtl allen 200 Feldern des Array den wert '' bzw 'leer' geben?

_________________
I believe that every human has a finite number of heart-beats. I don't intend to waste any of mine running around doing exercises.
- Neil Armstrong
Muetze1
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 346



BeitragVerfasst: Di 12.04.05 23:19 
Moin!


  • Was für eine Art von Array ist denn Koordinaten[] ? Statisch oder dynamisch?
  • Wie initialisierst du das Array bisher?
  • Wie gross ist es? Ist vielleicht die x oder y Koordinate grösser als das Koordinaten[] Array? (Brechpunkt mit Bedingungen...)


MfG
Muetze1
delfiphan
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 2684
Erhaltene Danke: 32



BeitragVerfasst: Mi 13.04.05 00:01 
Es ist leider etwas spät, aber ich hab noch nen Kommentar zu wherecursor: Schau dir mal die Funktion ScreenToClient an.
curposx := mouse.CursorPos.X - form1.left - 8;ist keine gute Lösung.
Du solltest auch deinen Code unbedingt übersichtlicher darstellen.
DarkHunter Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starofftopic starofftopic star
Beiträge: 477

Win XP
D3 Prof, D2005 PE
BeitragVerfasst: Mi 13.04.05 20:48 
user profile icondelfiphan hat folgendes geschrieben:
Es ist leider etwas spät, aber ich hab noch nen Kommentar zu wherecursor: Schau dir mal die Funktion ScreenToClient an.
curposx := mouse.CursorPos.X - form1.left - 8;ist keine gute Lösung.
Du solltest auch deinen Code unbedingt übersichtlicher darstellen.


danke werde ich beherzigen

@muetze1
ausblenden Delphi-Quelltext
1:
Koordinate : array[0..20,0..10] of String;					

_________________
I believe that every human has a finite number of heart-beats. I don't intend to waste any of mine running around doing exercises.
- Neil Armstrong
Muetze1
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 346



BeitragVerfasst: Mi 13.04.05 23:57 
Moin!

Und schonmal mit Bedingungen am Brechpunkt beim Eintritt in die Procedure nachgeschaut, ob X grösser als 20 wird bzw Y grösser als 10 oder einer von beiden kleiner als 0??

MfG
Muetze1
DarkHunter Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starofftopic starofftopic star
Beiträge: 477

Win XP
D3 Prof, D2005 PE
BeitragVerfasst: Do 14.04.05 20:37 
user profile iconMuetze1 hat folgendes geschrieben:
Moin!

Und schonmal mit Bedingungen am Brechpunkt beim Eintritt in die Procedure nachgeschaut, ob X grösser als 20 wird bzw Y grösser als 10 oder einer von beiden kleiner als 0??

MfG
Muetze1


Ist nicht möglich, hab ich schon überprüft

_________________
I believe that every human has a finite number of heart-beats. I don't intend to waste any of mine running around doing exercises.
- Neil Armstrong
delfiphan
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 2684
Erhaltene Danke: 32



BeitragVerfasst: Do 14.04.05 21:55 
Wenn du dein Programm mit {$R+} kompilierst, welche Fehlermeldung erhältst du dann? (Einfach {$R+} in die allererste Zeile des Programmes einfügen)
DarkHunter Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starofftopic starofftopic star
Beiträge: 477

Win XP
D3 Prof, D2005 PE
BeitragVerfasst: Do 14.04.05 22:08 
was heißt denn {$R+}??
delfiphan
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 2684
Erhaltene Danke: 32



BeitragVerfasst: Do 14.04.05 22:26 
Probier's mal mit der F1 Taste... {$R+}=Range Check. Es wird dann bei jedem Zugriff auf ein Array überprüft, ob der Zugriff möglich ist. Falls nicht, kriegst du eine Range Exception mit einer genauerern Fehlermeldung als nur "Access Violation". Du kannst auch zusätzlich noch {$Q+} einschalten (=Overflow Checks bei Zahlen).
Macht den Code langsamer, ist aber zum Debuggen noch gut.