Добавил:
Upload Опубликованный материал нарушает ваши авторские права? Сообщите нам.
Вуз: Предмет: Файл:
Скачиваний:
5
Добавлен:
26.04.2015
Размер:
13 Кб
Скачать
unit Unit6;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, StdCtrls, ComCtrls, XPMan, Grids, ExtCtrls;

type
Person=record     //запись
  Name:string[20];
  Age:integer;
  Sex:string[10];
  end;

type
  t_Tuning=(CD,Alarm,Condition);  //Перечисляемый тип
  tName=(BlueBird, SkyLite, Pajero, Carib);
   tMotor=record    //запись
    Name:tName;
    Price:Integer;
    Tuning:Set of t_Tuning; //множество
   end;

type
  familii=record
    name:string[30];
  end;

type
TKind = (GOLD, SILVER, BRONZE);//тип медали //перечисляемый тип
// запись файла
TMedal=record   //запись
person: string[40]; // спортсмен
country: string[20]; // страна
sport: string[20]; // вид спорта
kind: TKind; // медаль
end;


type
  TForm6 = class(TForm)
    XPManifest1: TXPManifest;
    PageControl1: TPageControl;
    TabSheet1: TTabSheet;
    PageControl6: TPageControl;
    TabSheet14: TTabSheet;
    GroupBox9: TGroupBox;
    Button17: TButton;
    ListBox21: TListBox;
    GroupBox10: TGroupBox;
    Label9: TLabel;
    Label10: TLabel;
    ListBox22: TListBox;
    ListBox23: TListBox;
    ListBox24: TListBox;
    Button20: TButton;
    ListBox25: TListBox;
    Button2: TButton;
    GroupBox1: TGroupBox;
    ListBox1: TListBox;
    Button5: TButton;
    TabSheet15: TTabSheet;
    Label2: TLabel;
    Label3: TLabel;
    Label4: TLabel;
    Label5: TLabel;
    StringGrid1: TStringGrid;
    StringGrid2: TStringGrid;
    StringGrid3: TStringGrid;
    Button1: TButton;
    TabSheet5: TTabSheet;
    Label12: TLabel;
    GroupBox6: TGroupBox;
    Button8: TButton;
    Edit5: TEdit;
    Button10: TButton;
    Button11: TButton;
    Edit6: TEdit;
    Button12: TButton;
    ListBox2: TListBox;
    Button9: TButton;
    Edit4: TEdit;
    GroupBox7: TGroupBox;
    Button13: TButton;
    Edit7: TEdit;
    Button15: TButton;
    GroupBox8: TGroupBox;
    Edit8: TEdit;
    Button16: TButton;
    Button18: TButton;
    Memo1: TMemo;
    Button19: TButton;
    Memo2: TMemo;
    TabSheet3: TTabSheet;
    GroupBox2: TGroupBox;
    Label6: TLabel;
    Label7: TLabel;
    Label8: TLabel;
    Edit1: TEdit;
    Edit2: TEdit;
    ComboBox1: TComboBox;
    StringGrid4: TStringGrid;
    Button6: TButton;
    Label13: TLabel;
    Label14: TLabel;
    Label1: TLabel;
    Label15: TLabel;
    Button7: TButton;
    GroupBox11: TGroupBox;
    Label18: TLabel;
    Label19: TLabel;
    Label20: TLabel;
    Label21: TLabel;
    Label22: TLabel;
    Edit9: TEdit;
    ComboBox4: TComboBox;
    ComboBox5: TComboBox;
    RadioGroup1: TRadioGroup;
    RadioButton5: TRadioButton;
    RadioButton6: TRadioButton;
    RadioButton7: TRadioButton;
    Button14: TButton;
    procedure FormClose(Sender: TObject; var Action: TCloseAction);
    procedure Button2Click(Sender: TObject);
    procedure Uporyadochivanie(Sender: TObject);
    procedure Button20Click(Sender: TObject);
    procedure Button4Click(Sender: TObject);
    procedure Button5Click(Sender: TObject);
    procedure Button17Click(Sender: TObject);
    procedure FormCreate(Sender: TObject);
    procedure Button1Click(Sender: TObject);
    procedure Button6Click(Sender: TObject);
    procedure Button7Click(Sender: TObject);
    procedure Button9Click(Sender: TObject);
    procedure Button8Click(Sender: TObject);
    procedure Button10Click(Sender: TObject);
    procedure Button11Click(Sender: TObject);
    procedure Button12Click(Sender: TObject);
    procedure Button13Click(Sender: TObject);
    procedure Button14Click(Sender: TObject);
    procedure Edit9MouseDown(Sender: TObject; Button: TMouseButton;
      Shift: TShiftState; X, Y: Integer);
    procedure Button15Click(Sender: TObject);
    procedure Button16Click(Sender: TObject);
    procedure Button18Click(Sender: TObject);
    procedure Button19Click(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;
type
  str=string[30];
var
  Form6: TForm6;
  MASSIV:array[1..50] of real;
  y,i,l,j,k:integer;
  Mat1,Mat2,Mat3:array[1..4,1..4] of Real;
  XXX:Person;
  Motor1:tMotor;
  Motor2:tMotor;
  Price1:set of #48..#57;
  ListMotor:array[1..10] of tMotor;
  rand:integer;
  turn:string;
  F2:str; //файловая переменная
  NM:string[30];
  F1:file of Str;//название файла
  FF:Text;
  Files:string[30];//Путь к файлу
  WinFile:string[30];//
  Text:string[30];//
  Y1:array[1..10] of string;

  H:integer;
  medal:Tmedal;
implementation

uses Unit1, Unit5;

{$R *.dfm}

procedure TForm6.FormClose(Sender: TObject; var Action: TCloseAction);
begin
Form1.Show;
end;

//-------Заполнение вещественного массива-------
//-------случайным образом (RANDOM)-------------
//-------и его вывод в ListBox----------------
//-------его сортировко-----------------------
//-------на положительные и отрицательные-----
procedure TForm6.Button2Click(Sender: TObject);
var
max,min:real;
g,p:integer;
Mas1,Mas2:string;
begin
randomize();
ListBox22.Clear;
ListBox23.Clear;
ListBox24.Clear;
for i:=1 to 50 do
begin
  MASSIV[i]:=Random(61)-30;
  ListBox22.Items.Add(FloatToStr(MASSIV[i]));
  if (MAssiv[i]>=0) then
  begin
    ListBox23.Items.Add(FloatToStr(massiv[i]))
  end
  else ListBox24.Items.Add(floattostr(massiv[i]));
  ListBox25.Clear;

  //MAX, MIN
max:=massiv[1];
min:=massiv[1];
g:=1;
p:=1;
 for J:=1 to 50 do
   begin
     if (Min>Massiv[j]) then
      begin
        Min:=massiv[j];
        g:=j;
      end;
   end;
   Mas1:='Max '+ FloatToStr(max)+'   № '+IntToStr(g);
     Label3.Caption:=Mas1;
  for j:=1 to 50 do
    begin
      if(Max<massiv[j]) then
        begin
          Max:=massiv[j];
          P:=j;
        end;
    end;
  Mas2:='Min '+ FloatToStr(min)+'   № '+IntToStr(p);
  Label4.Caption:=Mas2;
end;

end;
Procedure TForm6.Uporyadochivanie(Sender: TObject);
var
j,g:integer;
Min:Real;
begin
ListBox25.Clear;
for j:=1 to 49 do
  begin
    min:=MASSIV[j];
    g:=j;
    for i:=j to 50 do
      if (Min>MASSIV[i]) then
        begin
          min:=MASSIV[i];
          g:=i;
        end;
      MASSIV[g]:=MASSIV[j];
      MASSIV[j]:=min;
  end;
  for i:=1 to 50 do
    begin
    ListBox25.Items.Add(FloatToStr(MASSIV[i]));
    end;
end;

procedure TForm6.Button20Click(Sender: TObject);
begin
Uporyadochivanie(Sender);
end;

procedure TForm6.Button4Click(Sender: TObject);
var
N:integer;
begin
N:=StrToInt(InputBox('s','d',''));
for i:=n to 9 do
begin
massiv[n]:=massiv[n+1];
end;
ListBox1.Clear;
for i:=1 to 9 do
begin
  ListBox1.Items.Add(FloatToStr(massiv[i]));
end;

end;

procedure TForm6.Button5Click(Sender: TObject);
var
Str:string;
begin
ListBox1.Clear;
Y1[1]:='один';
Y1[2]:='два';
Y1[3]:='три';
Y1[4]:='четыре';
Y1[5]:='пять';
Y1[6]:='шесть';
Y1[7]:='семь';
Y1[8]:='восемь';
Y1[9]:='девять';
Y1[10]:='десять';
for i:=1 to 10 do
begin
  ListBox1.Items.Add(Y1[i]);
end;
end;

//---------Вывод кодов ASCII--------------------
procedure TForm6.Button17Click(Sender: TObject);
var
C:char;
n:integer;
i:Byte;
  begin
  ListBox21.Clear;
  C:=High(C);
  n:=ord(C);
  for i:=32 to n do
    begin
      C:=Char(i);
      ListBox21.Items.Add(' '+C+' ');
    end;
end;

procedure TForm6.FormCreate(Sender: TObject);
begin
Files:=Edit4.Text+'\'+Edit5.Text;
WinFile:=Edit4.Text+'\'+Edit7.Text;
Text:=Edit4.Text+'\'+Edit8.Text+'.txt';
for i:=0 to 4 do
begin
StringGrid1.Cells[0,i]:=IntToStr(i);
StringGrid1.Cells[i,0]:=IntToStr(i);
StringGrid2.Cells[0,i]:=IntToStr(i);
StringGrid2.Cells[i,0]:=IntToStr(i);
StringGrid3.Cells[0,i]:=IntToStr(i);
StringGrid3.Cells[i,0]:=IntToStr(i);
end;
begin
StringGrid4.Cells[0,0]:='№';
StringGrid4.Cells[0,1]:='Имя';
StringGrid4.Cells[0,2]:='Возраст';
StringGrid4.Cells[0,3]:='Пол';
end;
for i:=1 to 6 do
begin
StringGrid4.Cells[0,i]:=IntToStr(i);
end;
//----------------------------------
ComboBox1.Items.Add('Мужской');
ComboBox1.Items.Add('Женский');
k:=1;
//-----------------------------------

end;




//----------Произведение матриц-----------------
procedure TForm6.Button1Click(Sender: TObject);
begin
randomize();
for i:=1 to 4 do
  for j:=1 to 4 do
    begin
      Mat1[i,j]:=random(40)-20;//-----Создание двумерных-----
      Mat2[i,j]:=random(40)-20;//----------массивов----------

      StringGrid1.Cells[i,j]:=FloatToStr(Mat1[i,j]);//---Вывод массивов---
      StringGrid2.Cells[i,j]:=FloatToStr(Mat2[i,j]);//---в StringGrid-----
    end;

for i:=1 to 4 do //Сложение матриц
  for j:=1 to 4 do
begin
  Mat3[i,j]:=Mat1[i,j]+Mat2[i,j];
end;

// вывод в StringGrid
for y:=1 to 4 do
   for l:=1 to 4 do
      begin
         StringGrid3.Cells[y,l]:=FloatToStr(Mat3[y,l]);
      end;
end;

procedure TForm6.Button6Click(Sender: TObject);
begin
XXX.Name:=Edit1.Text;
XXX.Age:=StrToInt(Edit2.Text);
if (ComboBox1.Text='Мужской') then StringGrid4.Cells[3,k]:='Муж'
else StringGrid4.Cells[3,k]:='Жен';
StringGrid4.Cells[1,k]:=XXX.Name;
StringGrid4.Cells[2,k]:=IntToStr(XXX.Age);
//StringGrid4.Cells[3,k]:=XXX.Sex;
k:=k+1
end;

procedure TForm6.Button7Click(Sender: TObject);
var
SA:string;
begin
if RadioButton5.Enabled=true then SA:='GOLD';
if RadioButton6.Enabled=true then SA:='SILVER';
if RadioButton7.Enabled=true then SA:='BRONZE';
ShowMessage(Edit9.Text+' '+ComboBox4.Text+' '+ComboBox5.Text+' '+SA);
end;

procedure TForm6.Button9Click(Sender: TObject);
var
Put:string;
begin
Put:=Edit4.Text;
CreateDir(Put); //Создание каталога
end;

//Создание типизированного файла
procedure TForm6.Button8Click(Sender: TObject);
begin
Files:=Edit4.Text+'\'+Edit5.Text;
WinFile:=Edit4.Text;
AssignFile(F1, Files); // Связь файловой переменной с файлом.
Rewrite(F1); //  Создание или открытие файла
CloseFile(F1); // закрытие файла
end;



//Запись в типизированный файл
procedure TForm6.Button10Click(Sender: TObject);
var
Names:String[30];
begin
AssignFile(F1,Files);
Reset(F1);//открытие файла
for i:=1 to 5 do
begin
  Names:=InputBox('Запись в типизированный файл','Введите фамилю','');
  Write(F1,Names);
end;
CloseFile(F1);
end;


//Считывание из тип.файла конкретной записи
procedure TForm6.Button11Click(Sender: TObject);
var
N:integer;
NN:string;
begin
AssignFile(F1,Files);
Reset(F1);
N:=StrToInt(InputBox('Считывание из файла','Введите номер записи',''));
if (N-1>FileSize(F1)) then   ShowMessage('Введенное число больше количества записей в файле')
else
 begin
    Seek(F1,N-1); // переход на 3 запись
    Read(F1,F2); // чтение текущей записи
    Edit6.Text:=F2;
 end;
CloseFile(F1);
end;


//Считывание всех записей типизированного файла
procedure TForm6.Button12Click(Sender: TObject);
var
NNN:ShortString;
begin
AssignFile(F1,Files);
Reset(F1);
for i:=0 to FileSize(F1)-1 do
  BEGIN
    Seek(F1,i);//Переход на текущую запись
    Read(F1,F2);
    ListBox2.Items[i]:=F2;
  END;
end;


//Создание Windows-файла
procedure TForm6.Button13Click(Sender: TObject);
begin
if FileExists(WinFile)=true then begin DeleteFile(WinFile) end
else H:=FileCreate(WinFile);
FileClose(H);
end;
//Запись в файл
procedure TForm6.Button14Click(Sender: TObject);
var
W:str;
begin
H:=FileOpen(WinFile,fmOpenWrite);
AssignFile(F1,Files);
Reset(F1);
for i:=0 to filesize(F1)-1 do
begin
  seek(F1,i);
  Read(F1,F2);
  FileWrite(H,W,SizeOf(W))
end;
FileSeek(H,0,0);
for i:=0 to filesize(F1)-1 do
begin
FileRead(H,W,20);
end;
FileClose(H);
CloseFile(F1);
Button10.Enabled:=true;
end;

procedure TForm6.Edit9MouseDown(Sender: TObject; Button: TMouseButton;
Shift: TShiftState; X, Y: Integer);
begin
Edit9.SelectAll;
end;

procedure TForm6.Button15Click(Sender: TObject);
var
Nomer:integer;
Y:str;
Size:Byte;
SS:integer;
SSS:TMedal;
W:str;
begin
H:=FileOpen(WinFile,fmOpenRead);
Size:=SizeOf(W);
nomer:=StrToInt(InputBox('Считывание из Windows-фала','Введите номер записи',''));
FileSeek(H,(nomer-1)*Size,1);
FileRead(H,Y,1*Size);
ShowMessage(Y);
FileClose(H);
end;

//Создание текстового файла
procedure TForm6.Button16Click(Sender: TObject);
begin
AssignFile(FF,Text);//Связь файловой переменной с файлом
ReWrite(FF);//Создание текстового файла
CloseFile(FF);//Закрытие файла
Button18.Enabled:=true;
end;


//Запись в файл
procedure TForm6.Button18Click(Sender: TObject);
var
M:string;
begin
AssignFile(FF,Text);
i:=StrToInt(InputBox('Запись в файл из мемо','Введите номер строки',''));
M:=Memo1.Lines[i-1];
Append(FF);
WriteLn(FF,M);
CloseFile(FF);
button19.Enabled:=true;
end;

procedure TForm6.Button19Click(Sender: TObject);
var
S:string;
begin
Memo2.Clear;
AssignFile( FF,Text); //связь переменной с текстовым файлом
  Reset(FF);                          //открытие файла
  i:=0;
  while not EOF(FF) do        //цикл чтения в мемо
   begin
    ReadLn(FF,S);             //Чтение в строковую переменную
    Memo2.Lines.Append(S);      //Заполнение мемо
    i:=i+1;
   end;
  CloseFile(FF);              //Закрытие файла
end;

end.
Соседние файлы в папке Данные
  • #
    26.04.2015306 б5Unit5.dfm
  • #
    26.04.2015566 б5Unit5.pas
  • #
    26.04.201523 Кб5Unit6.dcu
  • #
    26.04.201551 б6Unit6.ddp
  • #
    26.04.201522 Кб6Unit6.dfm
  • #
    26.04.201513 Кб5Unit6.pas
  • #
    26.04.20153 Кб5Unit7.dcu
  • #
    26.04.201551 б5Unit7.ddp
  • #
    26.04.2015308 б5Unit7.dfm
  • #
    26.04.2015320 б5Unit7.pas
  • #
    26.04.20153 Кб5Unit8.dcu