Autor Beitrag
Wolle92
ontopic starontopic starontopic starontopic starontopic starofftopic starofftopic starofftopic star
Beiträge: 1296

Windows Vista Home Premium
Delphi 7 PE, Delphi 7 Portable, bald C++ & DirectX
BeitragVerfasst: Sa 28.07.07 10:19 
Hallo,
ich bin neben dem FTP-Clienten im Moment auch dabei, ein mensch-ärgere-dich-nicht-Spiel zu programmieren, und habe in der OnCreate-Procedure eine for-Schleife, um die farben der einzelnen Felder festzulegen...
Aber wenn ich jetzt das Programm starte, bekomme ich eine Access Violation...
Ohne die Schleife läuft es...
ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
for i := 1 to 72 do
begin
  //besetzt-Variablen festlegen
  if i > 56 then
    fields[i].taken := false
  else
    fields[i].taken := true;
  //farbe festlegen
  if i < 41 then
    fields[i].color := white;
  if ((i > 40) and (i < 45)) or ((i > 56) and (i < 61)) then
    fields[i].color := red;
  if ((i > 44) and (i < 49)) or ((i > 60) and (i < 65)) then
    fields[i].color := green;
  if ((i > 48) and (i < 53)) or ((i > 64) and (i < 69)) then
    fields[i].color := yellow;
  if ((i > 52) and (i < 57)) or ((i > 68) and (i < 73)) then
    fields[i].color := blue;
end;
Xion
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
EE-Maler
Beiträge: 1952
Erhaltene Danke: 128

Windows XP
Delphi (2005, SmartInspect), SQL, Lua, Java (Eclipse), C++ (Visual Studio 2010, Qt Creator), Python (Blender), Prolog (SWIProlog), Haskell (ghci)
BeitragVerfasst: Sa 28.07.07 10:30 
Hi,

wo genau kommt die Access Violation? Das würde sehr helfen...

hab da 3 Ideen:
:arrow: du hast ein dynamisches Array "fields" und das nicht initialisiert ( SetLength(fields,73); )
:arrow: dein array geht von 0 bis 71 (Länge ist dann 72), du fängst aber bei 1 an und läufst bis 72. Ein dynamisches Array fängt IMMER bei 0 an!
:arrow: "field" ist kein record, sondern eine class, somit musst du zu jedem Feld noch schreiben: fields[A]:=TField.Create;

Sind alles nur Vermutungen :lol:

Xion

_________________
a broken heart is like a broken window - it'll never heal
In einem gut regierten Land ist Armut eine Schande, in einem schlecht regierten Reichtum. (Konfuzius)
Wolle92 Threadstarter
ontopic starontopic starontopic starontopic starontopic starofftopic starofftopic starofftopic star
Beiträge: 1296

Windows Vista Home Premium
Delphi 7 PE, Delphi 7 Portable, bald C++ & DirectX
BeitragVerfasst: Sa 28.07.07 10:34 
Punkt 3 ist richtig, danke