Autor Beitrag
Dragonclaw
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 196

Windows Vista
Delphi 7 Prof.
BeitragVerfasst: Do 23.08.07 16:53 
Hallo!

Ich bin gerade dabei Minesweeper zu schreiben und versuche gerade die Buttons dynamisch zu erzeugen, dabei erhalte ich aber immer eine Accessvialation. Hier der Code

Erstellt das Minenfeld:
ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
procedure TfrMain.Create_Minefield(X_size, Y_size: Integer);
Var
  X, Y: Integer;
begin
for X := 1 to 9 do
  for Y := 1 to 9 do
    Create_Button('btn' + IntToStr(X) + IntToStr(Y),((x-1)*17),27+((y-1)*17),X,Y);
end;

procedure TfrMain.Create_Button(Name: String; X_kord, Y_kord, X, Y: Integer);
begin
  Minefield_buttons[X,Y] := TSpeedbutton.Create(self);
  with Minefield_buttons[X,Y] do
  begin
    Parent := frMain;
    left := X_kord;
    top := Y_kord;
  end;
end


Jetzt habe ich eine Procedur die nach dem Spiel aufräumen soll, hier der Teil der die Buttons in den Ausgangszustand zurückversetzen soll:

ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
  for X := 1 to 9 do
    for Y := 1 to 9 do
      begin
        Button := StringtoButton(X,Y);
        Button.Caption := '';
        Button.flat := False;
        Button.Enabled := True;
        Button.Glyph := nil;
        Button.Tag := 0;
      end;

StringtoButton ist eine Funktion die einfach einen bestimmten TSpeedbutton zurück liefert

Die Accessvialtation kommt ab Button.flat.

Kann mir jemand helfen?

Vielen Dank im vorraus.
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 23.08.07 17:10 
Moin!

Warum nicht so:
ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
  for X := 1 to 9 do
    for Y := 1 to 9 do
      begin
        Button := Minefield_buttons[X,Y];
        Button.Caption := '';
        Button.flat := False;
        Button.Enabled := True;
        Button.Glyph := nil;
        Button.Tag := 0;
      end;
cu
Narses

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

Windows Vista
Delphi 7 Prof.
BeitragVerfasst: Do 23.08.07 17:23 
Ahh okay, das klappt so. Warum das andere nicht geklappt hat ist mir aber schleierhaft.. naja egal.

Danke