Показать сообщение отдельно
  #3  
Старый 30.10.2011, 11:51
cyber922 cyber922 вне форума
Новичок
 
Регистрация: 07.10.2011
Сообщения: 77
Версия Delphi: Turbo Delphi 20
Репутация: 10
Восклицание

Код:
unit Unit1;
interface
uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, Buttons, StdCtrls, Grids;

type
  TForm1 = class(TForm)
    StringGrid1: TStringGrid;
    Edit1: TEdit;
    SpeedButton1: TSpeedButton;
    SpeedButton2: TSpeedButton;
    Edit2: TEdit;
    BitBtn1: TBitBtn;
    Label1: TLabel;
    Edit3: TEdit;
    Button2: TButton;
    Label2: TLabel;
    procedure SpeedButton1Click(Sender: TObject);
    procedure FormCreate(Sender: TObject);
    procedure SpeedButton2Click(Sender: TObject);
    procedure BitBtn1Click(Sender: TObject);
    procedure Button2Click(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

 type 
zap= record
NZ : string[6]; {номер записи}
fam: s15; {фамилия студента}
ball:array [1..3] of integer;{массив оценок по трем предметам}
end;
var
  Form1: TForm1;

implementation

{$R *.dfm}

procedure TForm1.FormCreate(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.BitBtn1Click(Sender: TObject);
begin
Close;
end;

procedure TForm1.Button2Click(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. 


Странно, у меня (f8), тут не ругается не на что. всё пропускает..
Ещё такой момент, как пишется функция которая при нажатии распечатывает на принтере..?

Десять раз код пересмотрел, вроде ниче криминального...



p.s. где написанно в описании записи "st15" не обращайите внимания, это я исправлю потом...
Ответить с цитированием