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: Fr 22.06.07 14:31 
Ich habe ein Problem, und zwar will ich bei einem Würfel, solange gewürfelt wird, immer das Würfel-Bild mit der Nummer, die grade vom PC ausgewählt wurde... Dafür habe ich ein Array erstellt, in dem die Grafiken erstellt werden sollen...
Den array definiere ich im "initialization"-Teil, aber ich bekomme immer eine EAccessViolation...
Was mache ich falsch?
ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
private
    { Private declarations }
    WuerfelArray: Array[1..6] of TImage;

...

initialization

Form1.WuerfelArray[1] := TImage.Create(Form1.Wuerfel1);
Form1.WuerfelArray[2] := TImage.Create(Form1.Wuerfel2);
Form1.WuerfelArray[3] := TImage.Create(Form1.Wuerfel3);
Form1.WuerfelArray[4] := TImage.Create(Form1.Wuerfel4);
Form1.WuerfelArray[5] := TImage.Create(Form1.Wuerfel5);
Form1.WuerfelArray[6] := TImage.Create(Form1.Wuerfel6);

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: Fr 22.06.07 14:37 
Zu diesem Zeitpunkt ist deine Form1 noch gar nicht erstellt.

Lager diesen Source mal in TForm.OnCreate um und lass das Form1 weg (oder schreib Self hin).

_________________
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.
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: Fr 22.06.07 14:44 
danke, hat geklappt
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: Fr 22.06.07 14:49 
aber was mache ich jetzt falsch?
Es wird immer nur der Würfel mit der 6 angezeigt...
ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
  while not wuerfeln_stop do
  begin
    WuerfelArray[gewuerfelt].Visible := false;
    gewuerfelt := Random(7);
    while gewuerfelt = 0 do
    begin
      gewuerfelt := Random(7);
    end;
    WuerfelArray[gewuerfelt].Visible := true;
    Application.ProcessMessages;
  end;
Marc.
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 1876
Erhaltene Danke: 129

Win 8.1, Xubuntu 15.10

BeitragVerfasst: Fr 22.06.07 14:55 
user profile iconWolle92 hat folgendes geschrieben:
aber was mache ich jetzt falsch?
Es wird immer nur der Würfel mit der 6 angezeigt...
ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
  while not wuerfeln_stop do
  begin
    WuerfelArray[gewuerfelt].Visible := false;
    gewuerfelt := Random(7);
    while gewuerfelt = 0 do
    begin
      gewuerfelt := Random(7);
    end;

    WuerfelArray[gewuerfelt].Visible := true;
    Application.ProcessMessages;
  end;

Oha. Wie wärs mit gewuerfelt := random(6)+1 ? :P

Hast du im FormCreate Randomize stehen?
Felux
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 57

WinXP Home + Sp1
D6 Pers(eng), D2005 Prof(de), Webocton Scriptly, C# (VS 2005 Express), Eclipse
BeitragVerfasst: Fr 22.06.07 14:56 
Du musst im Oncreate Ereignis noch den folgenden Befehl definieren:

ausblenden Delphi-Quelltext
1:
randomize;					



Dann solltest du mehr als nur die 6 beim Würfeln herausbekommen.
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: Fr 22.06.07 15:12 
ich bekomme ja immer was anderes raus... aber es wir immer nmur die 6 angezeigt, lasse das ja noch in einer Memo-Komponente ausgeben.. da steht dann "Du hast eine 4 gewürfelt" oder eben 1, 2, 3, 5 oder 6