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:
| unit Unit1;
interface
uses Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms, Dialogs, StdCtrls, ExtCtrls;
type TAufgabe = record Zahl : array of integer; Farbe : array of TColor; Ergebnis : integer; end; TForm1 = class(TForm) Button1: TButton; Image1: TImage; procedure Button1Click(Sender: TObject); private procedure ErstelleAufgaben(Anzahl,nummern: integer); procedure PrintAufgabe(nummer:integer); public end;
var Form1: TForm1; Aufgaben : array of TAufgabe;
const Farben: array[0..1] of TColor = (clRed,clBlue);
implementation
procedure TForm1.PrintAufgabe(nummer: integer); var i:integer; begin i := 0; Image1.Canvas.Font.Size := 12; Image1.Canvas.Font.Name := 'Courir New'; for i := 0 to Length(Aufgaben[nummer-1].Zahl) do begin Image1.Canvas.Font.Color := Aufgaben[nummer-1].Farbe[i]; Image1.Canvas.TextOut(20+(i*10),20,IntToStr(Aufgaben[nummer-1].Zahl[i])); end; end;
procedure TForm1.ErstelleAufgaben(Anzahl,nummern: integer); var i,q: integer; begin Randomize; if (Anzahl > 50) OR (Anzahl < 5) OR (nummern > 10) OR (nummern < 3) THEN MessageDlg('Es können nur 5 bis maximal 50 Aufgaben erstellt werden & 3 bis 10 nummern.',mtError,[mbOk],0) else begin SetLength(Aufgaben,Anzahl-1); for i := 0 to Anzahl-1 do begin SetLength(Aufgaben[i].Zahl,nummern-1); SetLength(Aufgaben[i].Farbe,nummern-1); repeat Aufgaben[i].Ergebnis := 0; for q := 0 to Nummern-1 do begin Aufgaben[i].Zahl[q] := random(9); Aufgaben[i].Farbe[q] := Farben[random(2)]; if (Aufgaben[i].Farbe[q] = clRed) then Aufgaben[i].Ergebnis := Aufgaben[i].Ergebnis + Aufgaben[i].Zahl[q] else Aufgaben[i].Ergebnis := Aufgaben[i].Ergebnis - Aufgaben[i].Zahl[q]; end; until (Aufgaben[i].ergebnis > -1) AND (Aufgaben[i].ergebnis < 10); end; PrintAufgabe(1); end; end;
{$R *.dfm}
procedure TForm1.Button1Click(Sender: TObject); begin ErstelleAufgaben(5,4); end;
end. |
Also das Prinzip ist eigentlich ganz einfach es ist noch nicht fertig geschrieben davon abgesehen aber es funktioniert ja auch nicht einmal...
Also unzwar in der "repeat" schleife
Wahrscheinlich genau nach oder in der if Abfrage
Wird Willkürlich ein Fehler produziert ...
Ich habe nicht herausfinden können was falsch ist
Teilweise Sagt er mir "Ungültige Zeigeroperation"
Teilwesie "Zugriffsverletzung"
Und mit der int. Fehlersuche kommt das CPU Fenster was mir persönlich nun gar nichts sagt ;x
Bitte um Rat