unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls, Spin, Grids;
type
TForm1 =
class(TForm)
Label1: TLabel;
StringGrid1: TStringGrid;
SpinEdit1: TSpinEdit;
SpinEdit2: TSpinEdit;
procedure SpinEdit1Change(Sender: TObject);
procedure SpinEdit2Change(Sender: TObject);
procedure FormCreate(Sender: TObject);
procedure multiwrite;
Procedure berechnung;
Procedure clenup;
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
procedure TForm1.SpinEdit1Change(Sender: TObject);
begin
clenup;
StringGrid1.ColCount := SpinEdit1.Value + 1;
multiwrite;
berechnung;
end;
procedure TForm1.SpinEdit2Change(Sender: TObject);
begin
clenup;
StringGrid1.RowCount := SpinEdit2.Value + 1;
multiwrite;
berechnung;
end;
procedure TForm1.FormCreate(Sender: TObject);
begin
StringGrid1.ColCount := SpinEdit1.Value + 1;
StringGrid1.RowCount := SpinEdit2.Value + 1;
multiwrite;
berechnung;
end;
procedure Tform1.multiwrite;
Var i : Integer;
Begin
//Die procedure multiwrite schreibe die erste Zeile und Spalte
StringGrid1.Cells[0,0] := '
x';
For i := 1
to SpinEdit1.Value
do
StringGrid1.Cells[i,0] := IntToStr(i);
For i := 1
to SpinEdit2.Value
do
StringGrid1.Cells[0,i] := IntToStr(i);
End;
Procedure TForm1.berechnung;
var i, x : Integer;
Begin
//berechnung berechnet und schreib die Werte in StringGrid1
For i := 1
to (SpinEdit2.Value)
do
Begin
For x := 1
to (SpinEdit1.Value)
do
Begin
StringGrid1.Cells[x,i] := IntToStr(StrToInt(StringGrid1.Cells[0,x])*StrToInt(StringGrid1.Cells[i,0]));
end;
end;
End;
Procedure TForm1.clenup;
var i, x : Integer;
Begin
//leert jedes Feld des Stringgrids
For i := 1
to (SpinEdit2.Value)
do
Begin
For x := 1
to (SpinEdit1.Value)
do
Begin
StringGrid1.Cells[x,i] := '
';
end;
end;
End;
end.