Hallo alle miteinander!
Ich bin noch recht neu mit Delphi und hab folgendes problem:
Ich möchte gerne das Spiel 4 gewinnt programmieren... allerdings bekomme ich immer iwelche access violations, wenn ich auf eins von den shapes klicke...
hier ist, was ich bisher habe:
//nicht erschrecken vor der länge...

- der part worum es geht ist eh nur sehr klein^^
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: 153: 154: 155: 156: 157: 158: 159: 160: 161: 162: 163: 164: 165: 166: 167: 168: 169: 170: 171: 172: 173:
| unit Unit1;
interface
uses Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms, Dialogs, StdCtrls, ExtCtrls;
type TForm1 = class(TForm) Shape1: TShape; Shape2: TShape; Shape3: TShape; Shape4: TShape; Shape5: TShape; Shape6: TShape; Shape7: TShape; Shape8: TShape; Shape9: TShape; Shape10: TShape; Shape11: TShape; Shape12: TShape; Shape13: TShape; Shape14: TShape; Shape15: TShape; Shape16: TShape; Shape17: TShape; Shape18: TShape; Shape19: TShape; Shape20: TShape; Shape21: TShape; Shape22: TShape; Shape23: TShape; Shape24: TShape; Shape25: TShape; Shape26: TShape; Shape27: TShape; Shape28: TShape; Shape29: TShape; Shape30: TShape; Shape31: TShape; Shape32: TShape; Shape33: TShape; Shape34: TShape; Shape35: TShape; Shape36: TShape; Shape37: TShape; Shape38: TShape; Shape39: TShape; Shape40: TShape; Shape41: TShape; Shape42: TShape; Label1: TLabel; Edit1: TEdit; Edit2: TEdit; procedure FormCreate(Sender: TObject); private procedure xy(Sender: TObject); procedure pruefe(Sender: TObject; Button: TMouseButton; Shift: TShiftState; X, Y: Integer); public end;
var Form1: TForm1; feld: array[1..7,1..6] of TShape; farbe:TColor; spalte,zeile:integer; const NamePrefix = 'Shape';
implementation
{$R *.dfm}
procedure TForm1.pruefe (Sender: TObject; Button: TMouseButton; Shift: TShiftState; X, Y: Integer); var gewonnen,p,i,n:integer; lol:Tcolor; begin xy(Tshape(Sender)); n:=1; p:=0; if farbe = clred then farbe := clyellow else farbe := clred; feld[1,1].brush.color := farbe; edit1.Text :=inttostr(spalte); edit2.Text :=inttostr(zeile);
end;
procedure TForm1.FormCreate(Sender: TObject); var i,x,y: Integer; begin for i := 1 to 42 do begin with TShape(FindComponent(NamePrefix + IntToStr(i))) do begin onmousedown :=pruefe; end; end;
for y:=1 to 7 do begin for x:=1 to 6 do begin feld[x,y]:=TShape(FindComponent(NamePrefix + IntToStr(i))); end; end; end;
procedure TForm1.xy(Sender: TObject); var i,a,b :integer; begin a:=1; b:=1; spalte:=1; zeile:=1; for i := 1 to 42 do begin if TShape(Sender) = TShape(FindComponent(NamePrefix + IntToStr(i))) then begin spalte := b; zeile := a; end else begin a := a+1; if a = 7 then begin a:=1; b:=b+1; end; end; end;
end;
end. |
wie gesagt, compilen kann ich, sobald ich allerdinfs auf eines der shapes klicke, würgt dat ding komplett ab :/
Ich glaube es liegt daran, dass ich die shapes iwie falsch auf den array gesetzt habe.. oder so ^^ sorry(feld[x,y]:=TShape(FindComponent(NamePrefix + IntToStr(i)))
Ich weiss nicht genau wie das richtig geht, und es wäre prima, wenn mir einer von euch weiterhelfen könnte
MfG
Euer Warheart
Moderiert von
Narses: Topic aus Sonstiges (Delphi) verschoben am Fr 02.05.2008 um 20:29