![]() |
|
|
|
|
#1
|
|||
|
|||
|
Код:
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, Grids, StdCtrls, Buttons;
type
TForm1 = class(TForm)
StringGrid1: TStringGrid;
SpeedButton1: TSpeedButton;
SpeedButton2: TSpeedButton;
SpeedButton3: TSpeedButton;
Button1: TButton;
Edit1: TEdit;
Edit2: TEdit;
Edit3: TEdit;
procedure OnCreate(Sender: TObject);
procedure SpeedButton1Click(Sender: TObject);
procedure SpeedButton2Click(Sender: TObject);
procedure SpeedButton3Click(Sender: TObject);
procedure Button1Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
procedure TForm1.Button1Click(Sender: TObject);
begin
Close;
end;
procedure TForm1.OnCreate(Sender: TObject);
begin
with StringGrid1 do begin
Cells[0,0] := '№/№';
Cells[1,0] := 'Фамилия';
Cells[2,0] := 'Математика';
Cells[3,0] := 'Физика';
Cells[4,0] := 'Химия';
Cells[5,0] := 'Средний балл';
ColCount:=6; FixedCols:=0;
end;
end;
procedure TForm1.SpeedButton1Click(Sender: TObject);
Var i,j : Byte;
F : File of Zap;
S :Zap;
begin
AssignFile(F, Edit1.Text);
Rewrite(F);
StringGrid1.RowCount:=StrToInt(Edit3.text);
For I := 1 to StringGrid1.RowCount-1 do with StringGrid1 do
Begin
S.NZ:= Cells[0,I];
S.fam := Cells[1,I];
S.ball[1]:=StrToInt( Cells[2,I]);
S.ball[2]:=StrToInt( Cells[3,I]);
S.ball[3]:=StrToInt( Cells[4,I]);
Write(F,S)
end;
CloseFile(F)
end;
procedure TForm1.SpeedButton2Click(Sender: TObject);
Var I : Byte;
F : File of Zap;
S : zap; Sr:real;
begin
AssignFile(F, Edit2.Text);
Reset(F); i:=1; seek(F,0);
while not eof(F) do
Begin
read(F,S);
StringGrid1.Cells[0,I]:=S.NZ;
StringGrid1.Cells[1,I]:=S.fam;
StringGrid1.Cells[2,I]:=IntToStr(S.ball[1]);
StringGrid1.Cells[3,I]:=IntToStr(S.ball[2]);
StringGrid1.Cells[4,I]:=IntToStr(S.ball[3]);
SR:=(S.ball[1]+S.ball[2]+S.ball[3])/3;
StringGrid1.Cells[5,I]:=FloatToStrF(SR,ffFixed,4,1);
i:=i+1;
end;
CloseFile(F)
end;
procedure TForm1.SpeedButton3Click(Sender: TObject);
var
i:integer;
begin
for i:=1 to StringGrid1.RowCount do begin
StringGrid1.Cells[0,I]:=' ';
StringGrid1.Cells[1,I]:=' ';
StringGrid1.Cells[2,I]:=' ';
StringGrid1.Cells[3,I]:=' ';
StringGrid1.Cells[4,I]:=' ';
StringGrid1.Cells[5,I]:=' ';
end;
end;
end.Вообщем перестаёт работать код уже с этой команды : F : File of Zap; Чёт, причину по которой он не работает не могу найти... Последний раз редактировалось Admin, 28.10.2011 в 17:13. |
|
#2
|
|||
|
|||
|
Не описано, что такое Zap.
Подозреваю, что запись: zap = record .....; .....; .....; end; |
|
#3
|
|||
|
|||
|
Цитата:
|
|
#4
|
|||
|
|||
|
Цитата:
Файлы объявляются следующим образом: Код:
var
f1 : File of <тип>; //типизированные файлы
f2 : TextFile; //текстовый тип файлов
f3 : File; //нетипизированные файлыОднако, присвоив какой-то переменной файловый тип, мы еще не можем работать с файлом. Для этого вначале надо связать эту переменную с файлом. Код:
AssignFile(f1, 'filename.txt'); //связывание переменной с файлом После этой функции, можем обращаться с переменной f1 как с файлом filename.txt. Если такого файла нет, получим ошибку, поэтому перед использованием связывания желательно делать проверку на наличие файла. Такая проверка проводится функцией Код:
FileExists(). |