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:
| procedure TForm1.FormCreate(Sender: TObject); begin Randomize; end;
procedure TForm1.SpeedButton1Click(Sender: TObject); var iX, iY: Integer; begin For iX := 1 to 5 do begin StringGrid1.Cells[iX, 0] := ''; For iY := 1 to 5 do begin StringGrid1.Cells[0, iY] := ''; StringGrid1.Cells[iX, iY] := IntToStr(Random(100) + 1); end; end; end;
procedure TForm1.SpeedButton2Click(Sender: TObject); var spalte, sum, iY: Integer; begin try spalte := StrToInt(InputBox('Spalte angeben', 'Welche Spalte (1-5) soll' + ' berechnet werden?', '')); except MessageDlg('Bitte geben Sie eine gültige Ganzzahl zwischen 1 und 5 ein.', mtError, [mbOk], 0); Exit; end; If (spalte < 1) or (spalte > 5) then begin MessageDlg('Die Spaltenzahl muss mindestens 1 und darf höchstens 5 betragen.', mtError, [mbOk], 0); Exit; end; sum := 0; try For iY := 1 to 5 do sum := sum + StrToInt(StringGrid1.Cells[spalte, iY]); except MessageDlg('Bitte führen Sie vorher ''Zufallszahlen erzeugen'' aus.', mtInformation, [mbOk], 0); Exit; end; StringGrid1.Cells[spalte, 0] := IntToStr(sum); end;
procedure TForm1.SpeedButton3Click(Sender: TObject); var zeile, sum, iX: Integer; begin try zeile := StrToInt(InputBox('Zeile angeben', 'Welche Zeile (1-5) soll' + ' berechnet werden?', '')); except MessageDlg('Bitte geben Sie eine gültige Ganzzahl zwischen 1 und 5 ein.', mtError, [mbOk], 0); Exit; end; If (zeile < 1) or (zeile > 5) then begin MessageDlg('Die Zeilenzahl muss mindestens 1 und darf höchstens 5 betragen.', mtError, [mbOk], 0); Exit; end; sum := 0; try For iX := 1 to 5 do sum := sum + StrToInt(StringGrid1.Cells[iX, zeile]); except MessageDlg('Bitte führen Sie vorher ''Zufallszahlen erzeugen'' aus.', mtInformation, [mbOk], 0); Exit; end; StringGrid1.Cells[0, zeile] := IntToStr(sum); end;
procedure TForm1.SpeedButton4Click(Sender: TObject); var iX, iY: Integer; begin For iX := 0 to 5 do for iY := 0 to 5 do StringGrid1.Cells[iX, iY] := ''; end;
procedure TForm1.SpeedButton5Click(Sender: TObject); begin Close; end; |