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:
| unit main;
interface
uses Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms, Dialogs, StdCtrls, Grids, Spin;
type TForm1 = class(TForm) GroupBox2: TGroupBox; Label3: TLabel; SpinEdit1: TSpinEdit; StringGrid1: TStringGrid; Button2: TButton; Button1: TButton; procedure FormCreate(Sender: TObject); procedure SpinEdit1Change(Sender: TObject); procedure Button2Click(Sender: TObject); procedure Button1Click(Sender: TObject); private public end;
var Form1: TForm1;
implementation
{$R *.dfm}
var states:Integer;
procedure TForm1.FormCreate(Sender: TObject); var i:Integer; begin for i:=1 to 5 do StringGrid1.Cells[0,i]:=' '+inttostr(i); end;
procedure TForm1.SpinEdit1Change(Sender: TObject); begin states:=SpinEdit1.Value; StringGrid1.RowCount:=states+1; end;
procedure TForm1.Button2Click(Sender: TObject); var f:File; temp:string[5]; i:Integer; begin AssignFile(f,'states.dat'); {$i-} rewrite(f); {$i+} IF IOResult<>0 then begin Application.MessageBox('Couldn''t save file ''states.dat''!','Error',16); exit; end; BlockWrite(f,states,sizeof(states)); for i:=1 to states do begin temp:=StringGrid1.Cells[1,i]; BlockWrite(f,temp,sizeof(temp)); temp:=StringGrid1.Cells[2,i]; BlockWrite(f,temp,sizeof(temp)); end; CloseFile(f); Application.MessageBox('File ''states.dat'' saved!','Information',64); end;
procedure TForm1.Button1Click(Sender: TObject); var f:file; temp:string[5]; i:Integer; begin AssignFile(f,'states.dat'); {$i-} reset(f); {$i+} IF IOResult<>0 then begin Application.MessageBox('Couldn''t open file ''states.dat''!','Error',16); exit; end; BlockRead(f,states,sizeof(states)); SpinEdit1.Value:=states; for i:=1 to states do begin BlockRead(f,temp,sizeof(temp)); StringGrid1.Cells[1,i]:=temp; BlockRead(f,temp,sizeof(temp)); StringGrid1.Cells[2,i]:=temp; end; CloseFile(f); Application.MessageBox('File ''states.dat'' opened!','Information',64); end;
end. |