Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- unit Unit1;
- interface
- uses
- Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants, System.Classes, Vcl.Graphics,
- Vcl.Controls, Vcl.Forms, Vcl.Dialogs, Vcl.Grids, Vcl.StdCtrls, Vcl.Menus;
- type
- TForm1 = class(TForm)
- Label1: TLabel;
- Edit1: TEdit;
- Button1: TButton;
- StringGrid1: TStringGrid;
- StringGrid2: TStringGrid;
- Label2: TLabel;
- StringGrid3: TStringGrid;
- Button2: TButton;
- Button3: TButton;
- Edit2: TEdit;
- OpenDialog1: TOpenDialog;
- SaveDialog1: TSaveDialog;
- PopupMenu1: TPopupMenu;
- MainMenu1: TMainMenu;
- N1: TMenuItem;
- N2: TMenuItem;
- N3: TMenuItem;
- N4: TMenuItem;
- N5: TMenuItem;
- N6: TMenuItem;
- procedure Button1Click(Sender: TObject);
- procedure Edit1KeyPress(Sender: TObject; var Key: Char);
- procedure StringGrid1SetEditText(Sender: TObject; ACol, ARow: Integer;
- const Value: string);
- procedure StringGrid2SetEditText(Sender: TObject; ACol, ARow: Integer;
- const Value: string);
- procedure Button2Click(Sender: TObject);
- procedure Edit2KeyPress(Sender: TObject; var Key: Char);
- procedure Button3Click(Sender: TObject);
- procedure Edit1Change(Sender: TObject);
- procedure Edit2Change(Sender: TObject);
- procedure StringGrid1KeyPress(Sender: TObject; var Key: Char);
- procedure StringGrid2KeyPress(Sender: TObject; var Key: Char);
- procedure N5Click(Sender: TObject);
- procedure N4Click(Sender: TObject);
- procedure N3Click(Sender: TObject);
- procedure N2Click(Sender: TObject);
- procedure N6Click(Sender: TObject);
- private
- { Private declarations }
- public
- { Public declarations }
- end;
- var
- Form1: TForm1;
- Path, Result : String;
- IsFileOpen, Flag, FlagButton : Boolean;
- implementation
- {$R *.dfm}
- procedure TForm1.Button1Click(Sender: TObject);
- var
- N, I, J : Integer;
- IsCorrect : Boolean;
- Const
- WIDE = 82;
- HEIGHT = 35;
- begin
- IsCorrect := True;
- Try
- N := StrToInt(Edit1.Text);
- Except
- MessageBox(Form1.Handle, Pchar('Проверьте корректность данных.'), 'Ошибка', MB_ICONSTOP);
- IsCorrect := False;
- StringGrid1.Visible := False;
- Edit1.Text := '';
- End;
- if IsCorrect then
- Begin
- StringGrid1.ColCount := N;
- //стоковые значения
- StringGrid1.ScrollBars := ssHorizontal;
- StringGrid1.Height := 55;
- StringGrid1.Width := WIDE * 5;
- If N < 6 then
- Begin
- StringGrid1.Height := HEIGHT;
- StringGrid1.ScrollBars := ssNone;
- case N of
- 1: StringGrid1.Width := WIDE;
- 2: StringGrid1.Width := WIDE * 2 + 1;
- 3: StringGrid1.Width := WIDE * 3;
- 4: StringGrid1.Width := WIDE * 4;
- end;
- End;
- for I := 0 to StringGrid1.RowCount - 1 do
- for J := 0 to StringGrid1.ColCount - 1 do
- StringGrid1.Cells[J, I] := '';
- StringGrid1.Visible := True;
- End;
- end;
- procedure TForm1.Button2Click(Sender: TObject);
- var
- N, I, J : Integer;
- IsCorrect : Boolean;
- Arr : Array of Integer;
- Const
- WIDE = 82;
- HEIGHT = 35;
- begin
- IsCorrect := True;
- Try
- N := StrToInt(Edit2.Text);
- Except
- MessageBox(Form1.Handle, Pchar('Проверьте корректность данных.'), 'Ошибка', MB_ICONSTOP);
- IsCorrect := False;
- StringGrid2.Visible := False;
- Edit2.Text := '';
- End;
- if IsCorrect then
- Begin
- StringGrid2.ColCount := N;
- //стоковые значения
- StringGrid2.ScrollBars := ssHorizontal;
- StringGrid2.Height := 55;
- StringGrid2.Width := WIDE * 5;
- If N < 6 then
- Begin
- StringGrid2.Height := HEIGHT;
- StringGrid2.ScrollBars := ssNone;
- case N of
- 1: StringGrid2.Width := WIDE;
- 2: StringGrid2.Width := WIDE * 2 + 1;
- 3: StringGrid2.Width := WIDE * 3;
- 4: StringGrid2.Width := WIDE * 4;
- end;
- End;
- for I := 0 to StringGrid2.RowCount - 1 do
- for J := 0 to StringGrid2.ColCount - 1 do
- StringGrid2.Cells[J, I] := '';
- StringGrid2.Visible := True;
- Button3.Enabled := True;
- End;
- end;
- procedure TForm1.Button3Click(Sender: TObject);
- Var
- Num1, Num2 : String;
- I : Integer;
- Float1, Float2 : Real;
- IsCorrect : Boolean;
- Const
- WIDE = 82;
- HEIGHT = 35;
- begin
- For I := 0 to StringGrid1.ColCount - 1 Do
- Num1 := Num1 + StringGrid1.Cells[I, 0];
- For I := 0 to StringGrid2.ColCount - 1 Do
- Num2 := Num2 + StringGrid2.Cells[I, 0];
- IsCorrect := True;
- Try
- Float1 := StrToFloat(Num1);
- Except
- IsCorrect := False;
- MessageBox(Form1.Handle, Pchar('Проверьте корректность данных в числе 1.'), 'Ошибка', MB_ICONSTOP);
- End;
- If IsCorrect then
- Begin
- Try
- Float2 := StrToFloat(Num2);
- Except
- IsCorrect := False;
- MessageBox(Form1.Handle, Pchar('Проверьте корректность данных в числе 2.'), 'Ошибка', MB_ICONSTOP);
- End;
- End;
- If IsCorrect then
- begin
- Float1 := Float1/Float2;
- Num1 := FloatToStr(Float1);
- StringGrid3.ColCount := Num1.Length;
- Result := Num1;
- //стоковые значения
- StringGrid3.ScrollBars := ssHorizontal;
- StringGrid3.Height := 55;
- StringGrid3.Width := WIDE * 5;
- If Num1.Length < 6 then
- Begin
- StringGrid3.Height := HEIGHT;
- StringGrid3.ScrollBars := ssNone;
- case Num1.Length of
- 1: StringGrid3.Width := WIDE;
- 2: StringGrid3.Width := WIDE * 2 + 1;
- 3: StringGrid3.Width := WIDE * 3;
- 4: StringGrid3.Width := WIDE * 4;
- end;
- End;
- For I := 1 To Num1.Length Do
- begin
- StringGrid3.Cells[I - 1, 0] := Num1[I];
- end;
- StringGrid3.Visible := True;
- end;
- end;
- procedure TForm1.Edit1Change(Sender: TObject);
- begin
- StringGrid3.Visible := False;
- If Length(Edit1.Text) = 0 then
- Begin
- Button1.Enabled := False;
- End
- else
- Begin
- Button1.Enabled := True;
- End;
- // Button3.Enabled := False;
- end;
- procedure TForm1.Edit1KeyPress(Sender: TObject; var Key: Char);
- begin
- if (Key = #13) and (Button1.Enabled) then
- Button1.Click;
- If (Not(Key In ['1'..'9', #08, #46])) Then
- Key := #0;
- If Key = '.' then
- Key := Char(0);
- end;
- procedure TForm1.Edit2Change(Sender: TObject);
- begin
- StringGrid3.Visible := False;
- If Length(Edit2.Text) = 0 then
- Button2.Enabled := False
- else
- Button2.Enabled := True;
- // Button3.Enabled := False;
- end;
- procedure TForm1.Edit2KeyPress(Sender: TObject; var Key: Char);
- begin
- if (Key = #13) and (Button2.Enabled) then
- Button2.Click;
- If (Not(Key In ['1'..'9', #08, #46])) Then
- Key := #0;
- If Key = '.' then
- Key := Char(0);
- end;
- Function Open (): String;
- Begin
- With Form1 Do
- Begin
- If OpenDialog1.Execute Then
- Begin
- Path := OpenDialog1.FileName;
- IsFileOpen := True;
- End
- Else
- IsFileOpen := False;
- End;
- Open := Path;
- End;
- function Check1 (N : String): Boolean;
- Var
- IsCorrect : Boolean;
- Temp : Real;
- Begin
- IsCorrect := True;
- try
- Temp := StrToFloat(N);
- except
- IsCorrect := False;
- MessageBox(Form1.Handle, Pchar('Не получилось считать число. Проверьте корректность данных.'), 'Ошибка', MB_ICONSTOP);
- end;
- Check1 := IsCorrect;
- End;
- function TakeNumbers (Var FileOutput: TextFile) : String;
- Var
- N : String;
- IsRight: Boolean;
- Begin
- IsRight := True;
- Try
- Readln(FileOutput, N);
- N := Trim (N);
- IsRight := Check1(N);
- Except
- End;
- If(Not(IsRight)) Then
- TakeNumbers := ''
- Else
- TakeNumbers := N;
- End;
- procedure TForm1.N2Click(Sender: TObject);
- Var
- FileInput: TextFile;
- N1, N2 : String;
- I : Integer;
- IsCorrect : Boolean;
- begin
- Path := Open;
- AssignFile(FileInput, Path);
- Reset(FileInput);
- If(IsFileOpen) Then
- Begin
- N1 := TakeNumbers(FileInput);
- End;
- If Not(N1 = '') then
- begin
- N2 := TakeNumbers(FileInput);
- end;
- If (N1 <> '') and (N2 <> '') and (StrToFloat(N2) <> 0) then
- Begin
- Edit1.Text := IntToStr(N1.Length);
- Button1Click(Sender);
- For I := 1 To N1.Length Do
- begin
- StringGrid1.Cells[I - 1, 0] := N1[I];
- end;
- Edit2.Visible := True;
- Button2.Visible := True;
- Label2.Visible := True;
- Edit2.Text := IntToStr(N2.Length);
- Button2Click(Sender);
- For I := 1 To N2.Length Do
- begin
- StringGrid2.Cells[I - 1, 0] := N2[I];
- end;
- Button3.Visible := True;
- End;
- If (StrToFloat(N2) = 0) then
- MessageBox(Form1.Handle, Pchar('На нуль делить нельзя! Проверьте корректность данных.'), 'Ошибка', MB_ICONSTOP);
- CloseFile(FileInput);
- end;
- procedure TForm1.N3Click(Sender: TObject);
- Var
- FileOutput: TextFile;
- IsCorrect : Boolean;
- begin
- IsCorrect := True;
- Path := Open;
- If (IsFileOpen) Then
- Begin
- try
- AssignFile(FileOutput, Path);
- Rewrite(FileOutput);
- Write(FileOutput, Result);
- except
- IsCorrect := False;
- Application.MessageBox('Запись в файл не удалась.', 'Ошибка', MB_ICONSTOP);
- end;
- if IsCorrect then
- Begin
- Application.MessageBox('Запись файла выполнена успешно.', 'Результат', 0);
- CloseFile(FileOutput);
- End;
- End;
- end;
- procedure TForm1.N4Click(Sender: TObject);
- begin
- Application.MessageBox('Программа делит 2 числа и выводит результат.'#13#10'Максимальное кол-во символов в числе: 9.'#13#10'При записи вещественных чисел используйте запятую (не точку).', 'Инструкция', 0);
- end;
- procedure TForm1.N5Click(Sender: TObject);
- begin
- Application.MessageBox('Арефин Владислав гр.251004', 'Разрабочик', 0);
- end;
- procedure TForm1.N6Click(Sender: TObject);
- begin
- Application.MessageBox('В файле должно быть 2 строчки с двумя числами', 'Инструкция к файлам', 0);
- end;
- procedure TForm1.StringGrid1KeyPress(Sender: TObject; var Key: Char);
- Var
- I : Integer;
- begin
- If (Not(Key In ['0'..'9', #08, #46, '-', ','])) Then
- Key := #0;
- With Sender As TStringGrid Do
- If (Length(StringGrid1.Cells[Col, Row]) > 0) then
- If (Not(Key In [#08, #46])) Then
- Key := #0;
- end;
- procedure TForm1.StringGrid1SetEditText(Sender: TObject; ACol, ARow: Integer;
- const Value: string);
- var
- I : Integer;
- IsCorrect : Boolean;
- Temp : String;
- begin
- IsCorrect := True;
- StringGrid3.Visible := False;
- for I := 0 to StringGrid1.ColCount - 1 do
- If (Length(StringGrid1.Cells[I, 0]) = 0) Then
- begin
- //FlagButton := False;
- //StringGrid2.visible := False;
- Button2.Visible := False;
- Edit2.Visible := False;
- Label2.Visible := False;
- IsCorrect := False;
- end;
- If IsCorrect then
- begin
- //FlagButton := True;
- //StringGrid2.visible := True;
- Button2.Visible := True;
- Edit2.Visible := True;
- Label2.Visible := True;
- end;
- end;
- procedure TForm1.StringGrid2KeyPress(Sender: TObject; var Key: Char);
- begin
- If (Not(Key In ['0'..'9', #08, #46, '-', ','])) Then
- Key := #0;
- With Sender As TStringGrid Do
- If (Length(StringGrid2.Cells[Col, Row]) > 0) then
- If (Not(Key In [#08, #46])) Then
- Key := #0;
- end;
- procedure TForm1.StringGrid2SetEditText(Sender: TObject; ACol, ARow: Integer;
- const Value: string);
- var
- I : Integer;
- IsCorrect : Boolean;
- begin
- IsCorrect := True;
- StringGrid3.Visible := False;
- for I := 0 to StringGrid2.ColCount - 1 do
- If (Length(StringGrid2.Cells[I, 0]) = 0) Then
- begin
- //FlagButton := False;
- //StringGrid3.visible := False;
- Button3.Visible := False;
- IsCorrect := False;
- end;
- If IsCorrect then
- begin
- //FlagButton := True;
- //StringGrid3.visible := True;
- Button3.Visible := True;
- end;
- end;
- end.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement