Autor Beitrag
KSK | TigeR
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 32



BeitragVerfasst: Mo 27.11.06 20:24 
Hi!

Ich wollte ein kleines Spiel schreiben, und bin auch erst ganz am Anfang, aber jetzt hat sich schon das erste größere Problem gezeigt:

Ich möchte Variablen aus einer Datei laden und bekomme dabei eine Zugriffsverletzung. Hier mal der Quelltext der betroffenen Unit:

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:
66:
67:
68:
69:
70:
71:
72:
73:
74:
75:
76:
77:
78:
79:
80:
81:
82:
83:
84:
85:
86:
87:
88:
89:
90:
91:
92:
93:
94:
95:
96:
97:
98:
99:
100:
101:
102:
103:
104:
105:
106:
107:
108:
109:
110:
111:
112:
113:
114:
115:
116:
117:
118:
119:
120:
121:
122:
123:
124:
125:
126:
127:
128:
129:
130:
131:
132:
133:
134:
135:
136:
137:
138:
139:
140:
141:
142:
143:
144:
145:
146:
147:
148:
149:
150:
151:
152:
unit Unit3;

interface

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

type
  TFrame3 = class(TFrame)
    PlayChar1Button: TButton;
    PlayChar2Button: TButton;
    PlayChar3Button: TButton;
    GroupBox1: TGroupBox;
    GroupBox2: TGroupBox;
    GroupBox3: TGroupBox;
    GroupBox4: TGroupBox;
    GroupBox5: TGroupBox;
    GroupBox6: TGroupBox;
    StartButton: TButton;
    Char1KriegerMaennlichImage: TImage;
    Char2KriegerMaennlichImage: TImage;
    Char1DelButton: TButton;
    Char2DelButton: TButton;
    Char3DelButton: TButton;
    Char1AktualisButton: TButton;
    Char2AktualisButton: TButton;
    Char3AktualisButton: TButton;
    Auserwaehlter1Label: TLabel;
    Char1RasseLabel: TLabel;
    Char1AtkLabel: TLabel;
    Char1VerLabel: TLabel;
    Char1SpeedLabel: TLabel;
    Char1ManaLabel: TLabel;
    Char1HPLabel: TLabel;
    Char1SexLabel: TLabel;
    Char1LuckLabel: TLabel;
    Auserwaehlter2Label: TLabel;
    Char2RasseLabel: TLabel;
    Char2SexLabel: TLabel;
    Char2HPLabel: TLabel;
    Char2ManaLabel: TLabel;
    Char2AtkLabel: TLabel;
    Char2VerLabel: TLabel;
    Char2SpeedLabel: TLabel;
    Char2LuckLabel: TLabel;
    Auserwaehlter3Label: TLabel;
    Char3RasseLabel: TLabel;
    Char3SexLabel: TLabel;
    Char3HPLabel: TLabel;
    Char3ManaLabel: TLabel;
    Char3AtkLabel: TLabel;
    Char3VerLabel: TLabel;
    Char3SpeedLabel: TLabel;
    Char3LuckLabel: TLabel;
    procedure StartButtonClick(Sender: TObject);
    procedure PlayChar1ButtonClick(Sender: TObject);
    procedure PlayChar2ButtonClick(Sender: TObject);
    procedure PlayChar3ButtonClick(Sender: TObject);
    procedure Char1AktualisButtonClick(Sender: TObject);
    procedure Char2AktualisButtonClick(Sender: TObject);
    procedure Char3AktualisButtonClick(Sender: TObject);
  private
    { Private-Deklarationen }
  public
    { Public-Deklarationen }
  end;

implementation

uses Unit1;

{$R *.DFM}

procedure TFrame3.StartButtonClick(Sender: TObject);
var play, erstellen, lang, user, aktualis: String;
    ini, cfg, { char, } login: TIniFile;
  { god1, god2, god3: Boolean; }
begin
     cfg:=TIniFile.create(ExtractFilePath(ParamStr(0))+'config.cfg');
     lang:=cfg.ReadString('Language','lang','german');
     cfg.free;

     login:=TIniFile.create(ExtractFilePath(ParamStr(0))+'config.cfg');
     user:=login.ReadString('Login','Lastuser','');
     login.free;

     ini:=TIniFile.create(ExtractFilePath(ParamStr(0))+'language.ini');
     play:=ini.ReadString(lang,'spielen','Spielen');
     erstellen:=ini.ReadString(lang,'erstellen','Erstellen');
     aktualis:=ini.ReadString(lang,'aktualis','Aktualisieren');

     char:=TIniFile.create(ExtractFilePath(ParamStr(0))+'charakters.ini');

     god1:=char.ReadBool(user,'char1_god',False);
     god2:=char.ReadBool(user,'char2_god',False);
     god3:=char.ReadBool(user,'char3_god',False);

     GroupBox1.Caption:=char.ReadString(user,'char1_name','');
     if god1=True then Auserwaehlter1Label.Caption:=ini.ReadString(lang,'auserwaehlter','Auserwählter') else Auserwaehlter1Label.Caption:='';
     Char1RasseLabel.Caption:=ini.ReadString(lang,'char_rasse','Rasse')+': '+char.ReadString(user,'char1_rasse','?');
     Char1SexLabel.Caption:=ini.ReadString(lang,'char_sex','Geschlecht')+': '+char.ReadString(user,'char1_sex','?');
     Char1HPLabel.Caption:=ini.ReadString(lang,'char_hp','Health-Points')+': '+char.ReadString(user,'char1_hp','?');
     Char1ManaLabel.Caption:=ini.ReadString(lang,'char_mana','Mana')+': '+char.ReadString(user,'char1_mana','?');
     Char1AtkLabel.Caption:=ini.ReadString(lang,'char_atk','Angriff')+': '+char.ReadString(user,'char1_atk','?');
     Char1VerLabel.Caption:=ini.ReadString(lang,'char_ver','Verteidigung')+': '+char.ReadString(user,'char1_ver','?');
     Char1SpeedLabel.Caption:=ini.ReadString(lang,'char_speed','Geschwindigkeit')+': '+char.ReadString(user,'char1_speed','?');
     Char1LuckLabel.Caption:=ini.ReadString(lang,'char_luck','Glück')+': '+char.ReadString(user,'char1_luck','?');

     GroupBox2.Caption:=char.ReadString(user,'char2_name','');
     if god2=True then Auserwaehlter2Label.Caption:=ini.ReadString(lang,'auserwaehlter','Auserwählter') else Auserwaehlter2Label.Caption:='';
     Char2RasseLabel.Caption:=ini.ReadString(lang,'char_rasse','Rasse')+': '+char.ReadString(user,'char2_rasse','?');
     Char2SexLabel.Caption:=ini.ReadString(lang,'char_sex','Geschlecht')+': '+char.ReadString(user,'char2_sex','?');
     Char2HPLabel.Caption:=ini.ReadString(lang,'char_hp','Health-Points')+': '+char.ReadString(user,'char2_hp','?');
     Char2ManaLabel.Caption:=ini.ReadString(lang,'char_mana','Mana')+': '+char.ReadString(user,'char2_mana','?');
     Char2AtkLabel.Caption:=ini.ReadString(lang,'char_atk','Angriff')+': '+char.ReadString(user,'char2_atk','?');
     Char2VerLabel.Caption:=ini.ReadString(lang,'char_ver','Verteidigung')+': '+char.ReadString(user,'char2_ver','?');
     Char2SpeedLabel.Caption:=ini.ReadString(lang,'char_speed','Geschwindigkeit')+': '+char.ReadString(user,'char2_speed','?');
     Char2LuckLabel.Caption:=ini.ReadString(lang,'char_luck','Glück')+': '+char.ReadString(user,'char2_luck','?');

     GroupBox3.Caption:=char.ReadString(user,'char3_name','');
     if god3=True then Auserwaehlter1Label.Caption:=ini.ReadString(lang,'auserwaehlter','Auserwählter') else Auserwaehlter1Label.Caption:='';
     Char3RasseLabel.Caption:=ini.ReadString(lang,'char_rasse','Rasse')+': '+char.ReadString(user,'char3_rasse','?');
     Char3SexLabel.Caption:=ini.ReadString(lang,'char_sex','Geschlecht')+': '+char.ReadString(user,'char3_sex','?');
     Char3HPLabel.Caption:=ini.ReadString(lang,'char_hp','Health-Points')+': '+char.ReadString(user,'char3_hp','?');
     Char3ManaLabel.Caption:=ini.ReadString(lang,'char_mana','Mana')+': '+char.ReadString(user,'char3_mana','?');
     Char3AtkLabel.Caption:=ini.ReadString(lang,'char_atk','Angriff')+': '+char.ReadString(user,'char3_atk','?');
     Char3VerLabel.Caption:=ini.ReadString(lang,'char_ver','Verteidigung')+': '+char.ReadString(user,'char3_ver','?');
     Char3SpeedLabel.Caption:=ini.ReadString(lang,'char_speed','Geschwindigkeit')+': '+char.ReadString(user,'char3_speed','?');
     Char3LuckLabel.Caption:=ini.ReadString(lang,'char_luck','Glück')+': '+char.ReadString(user,'char3_luck','?');

     char.free;  
     ini.free;

     Char1AktualisButton.Caption:=aktualis;
     Char2AktualisButton.Caption:=aktualis;
     Char3AktualisButton.Caption:=aktualis;

     GroupBox1.Visible:=True;
     GroupBox2.Visible:=True;
     GroupBox3.Visible:=True;
     GroupBox4.Visible:=True;
     GroupBox5.Visible:=True;
     GroupBox6.Visible:=True;
     PlayChar1Button.Visible:=True;
     PlayChar2Button.Visible:=True;
     PlayChar3Button.Visible:=True;
     Char1AktualisButton.Visible:=True;
     Char2AktualisButton.Visible:=True;
     Char3AktualisButton.Visible:=True;
     StartButton.Visible:=False;
end;


Folgende Meldung erscheint, wenn ich das Programm von Delphi aus starte und den entsprechenden Button drücke:
"Im Projekt Project1.exe ist eine Exeption der Klasse EAccessViolation aufgetreten. Meldung: 'Zugriffsverletzung bei Adresse 7C923144 in Modul 'ntdll.dll'. Schreiben von Adresse 00403E55'. Prozeß wurde angehalten. Mit Einzelne Anweisung oder Start fortsetzen."

Was hat das zu bedeuten? Was kann ich gegen diesen Fehler tun?
Soweit ich das überblicken kann, habe ich keinen Syntaxfehler drin.

Moderiert von user profile iconraziel: Code- durch Delphi-Tags ersetzt
Blackheart666
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 2195

XP
D3Prof, D6Pers.
BeitragVerfasst: Mo 27.11.06 20:53 
Hallo
Könntest mal delphi Tags benutzen liest sich besser
ausblenden Delphi-Quelltext
1:
....					

Hab jetzt nicht weiter geschaut aber vieleicht könnte es daran liegen das Du zwei mal 'config.cfg' erzeugst.

_________________
Blackheart666
Der Irrsinn ist bei Einzelnen etwas Seltenes, - aber bei Gruppen, Parteien, Völkern, Zeiten die Regel. (Friedrich Nietzsche)
KSK | TigeR Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 32



BeitragVerfasst: Mo 27.11.06 21:09 
Daran hats gelegen! Hab ich doch vergessen den Dateinamen zu ändern.

Mann, ich bin echt blind!

:) Danke für die Hilfe, ohne dich wär ich wohl noch verzweifelt ^^