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.StdCtrls, Vcl.Grids, Vcl.Menus;
- type
- TForm1 = class(TForm)
- StringGrid1: TStringGrid;
- Edit1: TEdit;
- Edit2: TEdit;
- Label1: TLabel;
- Label2: TLabel;
- Label3: TLabel;
- Button1: TButton;
- MainMenu1: TMainMenu;
- PopupMenu1: TPopupMenu;
- OpenDialog1: TOpenDialog;
- SaveDialog1: TSaveDialog;
- N1: TMenuItem;
- N2: TMenuItem;
- N3: TMenuItem;
- N4: TMenuItem;
- N5: TMenuItem;
- procedure Button1Click(Sender: TObject);
- procedure StringGrid1KeyPress(Sender: TObject; var Key: Char);
- procedure Edit2Change(Sender: TObject);
- procedure Edit1KeyPress(Sender: TObject; var Key: Char);
- procedure Edit2KeyPress(Sender: TObject; var Key: Char);
- procedure StringGrid1SetEditText(Sender: TObject; ACol, ARow: Integer;
- const Value: string);
- procedure Edit1Change(Sender: TObject);
- procedure N4Click(Sender: TObject);
- procedure N5Click(Sender: TObject);
- procedure N2Click(Sender: TObject);
- procedure N3Click(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
- X, N, B, I, Count, Sum : Integer;
- Arr : Array of Integer;
- begin
- Try
- X := StrToInt(Edit1.Text);
- Except
- Application.MessageBox('Check data correctness!', 'Error', MB_ICONSTOP);
- Edit1.Text := '';
- End;
- Try
- N := StrToInt(Edit2.Text);
- Except
- Application.MessageBox('Check data correctness!', 'Error', MB_ICONSTOP);
- Edit2.Text := '';
- End;
- SetLength(Arr, N);
- Sum := 0;
- For I := Low(Arr) to High(Arr) do
- Begin
- If Length(StringGrid1.Cells[I, 0]) <> 0 then
- Arr[I]:= StrToInt(StringGrid1.Cells[I,0])
- else
- Arr[I] := 0;
- End;
- B := Arr[N - 1];
- For I := (N - 2) Downto 0 Do
- Begin
- B := Arr[I] + (B * X);
- End;
- Label3.Visible := true;
- Label3.Caption := 'Ответ: ' + IntToStr(B);
- end;
- procedure TForm1.Edit1KeyPress(Sender: TObject; var Key: Char);
- const
- MAX = 5;
- begin
- If ((Key = #13) And (Button1.Enabled)) Then
- Button1.Click;
- If (Not(Key In ['0'..'9', #08, #46, '-'])) Then
- Key := #0;
- If (Length(Edit1.Text) = MAX) Then
- If (Not(Key In [#08, #46])) Then
- Key := #0;
- If (Length(Edit1.Text) = 0) then
- If (Not(Key In ['1'..'9', #08, #46, '-'])) Then
- Key := #0;
- If (Length(Edit1.Text) <> 0) and (Key = '-')then
- Key := #0;
- end;
- procedure TForm1.StringGrid1SetEditText(Sender: TObject; ACol, ARow: Integer;
- const Value: string);
- Var
- I, J : Integer;
- begin
- Label3.Visible := False;
- FlagButton := true;
- for I := 0 to StringGrid1.RowCount - 1 do
- for J := 0 to StringGrid1.ColCount - 1 do
- If Length(StringGrid1.Cells[J, I]) = 0 Then
- FlagButton := false;
- If not(flag)then
- Button1.Enabled := False;
- If (Length(Edit1.Text) <> 0) and (Length(Edit2.Text) <> 0) and (FlagButton = true) then
- Button1.Enabled := True;
- end;
- procedure TForm1.Edit1Change(Sender: TObject);
- begin
- //N3.Enabled := False;
- If (Length(Edit1.Text) = 0)then
- Button1.Enabled := False;
- If (Length(Edit1.Text) <> 0) and (Length(Edit2.Text) <> 0) and (FlagButton = true) then
- Button1.Enabled := True;
- Label3.Visible := False;
- end;
- procedure TForm1.Edit2Change(Sender: TObject);
- var
- N: Integer;
- const
- MAX = 3;
- STEP = 81;
- THREE_CELLS = 246;
- HEIGHT = 57;
- STEP_H = 35;
- LEFT = 10;
- STEP_L2 = 45;
- STEP_L1 = 83;
- begin
- if Edit2.Text <> '' then
- Begin
- N := StrToInt(Edit2.Text);
- StringGrid1.ColCount := N;
- StringGrid1.Width := THREE_CELLS;
- StringGrid1.Height := HEIGHT;
- StringGrid1.Left := LEFT;
- if N = 3 then
- StringGrid1.Height := STEP_H;
- if N = 2 then
- Begin
- StringGrid1.Width := THREE_CELLS - STEP;
- StringGrid1.Height := STEP_H;
- StringGrid1.Left := LEFT + STEP_L2;
- End;
- if N = 1 then
- Begin //нахуя я это делал, это не надо было. N никогда не равно 1..
- StringGrid1.Width := THREE_CELLS - STEP - STEP;
- StringGrid1.Height := STEP_H;
- StringGrid1.Left := LEFT + STEP_L1;
- End;
- StringGrid1.Visible := True;
- End
- Else
- StringGrid1.Visible := False;
- //N3.Enabled := False;
- If (Length(Edit2.Text) = 0)then
- Button1.Enabled := False;
- If (Length(Edit2.Text) <> 0) and (Length(Edit2.Text) <> 0) and (FlagButton = true) then
- Button1.Enabled := True;
- Label3.Visible := False;
- end;
- procedure TForm1.Edit2KeyPress(Sender: TObject; var Key: Char);
- const
- MAX = 5;
- begin
- If ((Key = #13) And (Button1.Enabled)) Then
- Button1.Click;
- If (Not(Key In ['0'..'9', #08, #46])) Then
- Key := #0;
- If (Length(Edit2.Text) = MAX) Then
- If (Not(Key In [#08, #46])) Then
- Key := #0;
- if (Length(Edit2.Text) = 0) then
- If (Not(Key In ['2'..'9', #08, #46])) Then
- Key := #0;
- end;
- procedure TForm1.N4Click(Sender: TObject);
- begin
- Application.MessageBox('Программа вычисляет многочлен А1*x + А2*x^2 + А3*x^3 + ... + АN*x^N.'#13#10'Диапазон X: -9999...99999'#13#10'Диапазон N: 2...99999'#13#10'Диапазон элементов массива: -9999...99999', 'Инструкция', 0);
- end;
- procedure TForm1.N5Click(Sender: TObject);
- begin
- Application.MessageBox('Арефин Владислав гр.251004', 'Разрабочик', 0);
- end;
- procedure TForm1.StringGrid1KeyPress(Sender: TObject; var Key: Char);
- const // тут я сделал ввод онли integer цифр, тк мне впадлу делать real
- MAX = 4;
- begin
- If (Not(Key In ['0'..'9', #08, #46,',','-'])) Then
- Key := #0;
- With Sender As TStringGrid Do
- Begin
- If (Length(StringGrid1.Cells[Col, Row]) <> 0) and (Key = '-') then
- Key := Char(0);
- If (Length(StringGrid1.Cells[Col, Row]) > MAX) then
- If (Not(Key In [#08, #46])) Then
- Key := #0;
- End;
- end;
- Function CheckFileData1(Num: String): Boolean;
- Const
- MAX_LIM = 99999;
- MIN_LIM = -9999;
- Var
- NewNum: Real;
- IsCorrect: Boolean;
- Begin
- NewNum := 0;
- IsCorrect := True;
- Try
- NewNum := StrToFloat(Num);
- Except
- MessageBox(Form1.Handle, Pchar('Проверьте корректность данных.'), 'Ошибка', MB_ICONSTOP);
- IsCorrect := False;
- End;
- If(IsCorrect And ((NewNum > MAX_LIM) Or (NewNum < MIN_LIM))) Then
- Begin
- Num := FloatToStr(NewNum);
- MessageBox(Form1.Handle, Pchar('Недопустимое значение!'), 'Ошибка', MB_ICONSTOP);
- IsCorrect := False;
- End;
- CheckFileData1 := IsCorrect;
- End;
- Function CheckFileData2(Num: String): Boolean;
- Const
- MAX_LIM = 99999;
- MIN_LIM = 2;
- Var
- NewNum: Real;
- IsCorrect: Boolean;
- Begin
- NewNum := 0;
- IsCorrect := True;
- Try
- NewNum := StrToFloat(Num);
- Except
- MessageBox(Form1.Handle, Pchar('Проверьте корректность данных.'), 'Ошибка', MB_ICONSTOP);
- IsCorrect := False;
- End;
- If(IsCorrect And ((NewNum > MAX_LIM) Or (NewNum <= MIN_LIM))) Then
- Begin
- Num := FloatToStr(NewNum);
- MessageBox(Form1.Handle, Pchar('Недопустимое значение!'), 'Ошибка', MB_ICONSTOP);
- IsCorrect := False;
- End;
- CheckFileData2 := IsCorrect;
- 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 TakeDataFromFile1(Number1: String; Var FileOutput: TextFile): String;
- Var
- IsRight: Boolean;
- Begin
- IsRight := True;
- Try
- Readln(FileOutput, Number1);
- IsRight := CheckFileData1(Number1);
- Except
- End;
- If(Not(IsRight)) Then
- TakeDataFromFile1 := ''
- Else
- TakeDataFromFile1 := Number1;
- End;
- Function TakeDataFromFile2(Number2: String; Var FileOutput: TextFile): String;
- Var
- IsRight : Boolean;
- Begin
- IsRight := True;
- Try
- Read(FileOutput, Number2);
- IsRight := CheckFileData2(Number2);
- Except
- End;
- If(Not(IsRight)) Then
- TakeDataFromFile2 := ''
- Else
- TakeDataFromFile2 := Number2;
- End;
- procedure TForm1.N2Click(Sender: TObject);
- Var
- FileInput: TextFile;
- Num : Integer;
- Str1, Str2 : String;
- begin
- Num := 0;
- Path := Open;
- AssignFile(FileInput, Path);
- Reset(FileInput);
- If(IsFileOpen) Then
- Begin
- Str1 := TakeDataFromFile1(IntToStr(Num), FileInput);
- Str2 := TakeDataFromFile2(IntToStr(Num), FileInput);
- End;
- if (Length(Str1) > 0) then
- Begin
- Edit1.Text := Str1;
- End
- Else
- Edit1.Text := #0;
- If (Length(Str2) > 0) then
- Begin
- Edit2.Text := Str2;
- End
- Else
- Edit2.Text := #0;
- CloseFile(FileInput);
- end;
- procedure TForm1.N3Click(Sender: TObject);
- Var
- FileOutput: TextFile;
- begin
- Path := Open;
- If (IsFileOpen) Then
- Begin
- AssignFile(FileOutput, Path);
- Rewrite(FileOutput);
- Write(FileOutput, Result);
- Application.MessageBox('Запись файла выполнена успешно.', 'Результат', 0);
- CloseFile(FileOutput);
- Label3.Caption := '';
- Edit1.Text := '';
- Edit2.Text := '';
- End;
- end;
- end.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement