Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Unit Main;
- Interface
- Uses
- Winapi.Windows,
- Winapi.Messages,
- System.SysUtils,
- System.Variants,
- System.Classes,
- Vcl.Graphics,
- Clipbrd,
- Vcl.Controls,
- Vcl.Forms,
- Vcl.Dialogs,
- Vcl.StdCtrls,
- Vcl.Menus,
- Vcl.ExtCtrls,
- Vcl.Imaging.Pngimage;
- Type
- TMainForm = Class(TForm)
- Button1: TButton;
- EditA: TEdit;
- EditB: TEdit;
- MainMenu1: TMainMenu;
- N1: TMenuItem;
- N2: TMenuItem;
- N3: TMenuItem;
- N4: TMenuItem;
- N5: TMenuItem;
- Y1: TLabel;
- X: TLabel;
- BalloonHint1: TBalloonHint;
- OpenDialog1: TOpenDialog;
- SaveDialog1: TSaveDialog;
- Y: TLabel;
- Result: TMemo;
- LabelTask: TLabel;
- Procedure Button1Click(Sender: TObject);
- Procedure N2Click(Sender: TObject);
- Procedure N5Click(Sender: TObject);
- Procedure EditBKeyPress(Sender: TObject; Var Key: Char);
- Procedure EditAKeyPress(Sender: TObject; Var Key: Char);
- Procedure N3Click(Sender: TObject);
- Procedure GetPath(Var Path: String);
- Procedure N4Click(Sender: TObject);
- Procedure Checker(Var IsCorrect: Boolean);
- Procedure N1Click(Sender: TObject);
- Procedure EditAChange(Sender: TObject);
- Procedure EditBChange(Sender: TObject);
- Procedure FormMouseMove(Sender: TObject; Shift: TShiftState; X, Y: Integer);
- Procedure FormCloseQuery(Sender: TObject; Var CanClose: Boolean);
- Procedure EditAContextPopup(Sender: TObject; MousePos: TPoint; Var Handled: Boolean);
- Procedure EditBContextPopup(Sender: TObject; MousePos: TPoint; Var Handled: Boolean);
- Private
- { Private declarations }
- Public
- { Public declarations }
- End;
- Const
- E: Double = 1.0E-3;
- NumSet = ['0', '1', '2', '3', '4', '5', '6', '7', '8', '9', #8, #44, #45, #46];
- Var
- MainForm: TMainForm;
- Implementation
- {$R *.dfm}
- Uses
- Instruction,
- Information;
- Procedure TmainForm.Checker(Var IsCorrect: Boolean);
- Begin
- IsCorrect := True;
- Try
- StrtoFloat(EditA.Text);
- Except
- IsCorrect := False;
- End;
- Try
- StrtoFloat(EditB.Text);
- Except
- IsCorrect := False;
- End;
- End;
- Procedure TMainForm.Button1Click(Sender: TObject);
- Var
- A, B, R, I: Integer;
- IsCorrect: Boolean;
- Begin
- Checker(IsCorrect);
- If IsCorrect Then
- Begin
- A := StrtoInt(EditA.Text);
- B := StrtoInt(EditB.Text);
- R := 1;
- If (A < (B + 1)) Then
- Begin
- A := A - 1;
- for i := 0 to A do
- begin
- R := R*(B-I);
- end;
- Result.Lines.Clear;
- Result.Lines.Add('Число размещений равно ' +FloatToStr(R));
- End
- Else
- Begin
- ShowMessage('Введите верные значения, где N > M.');
- End;
- End
- Else
- Begin
- ShowMessage('Заполните все поля');
- End;
- End;
- Procedure TMainForm.EditBChange(Sender: TObject);
- Var
- Value: Double;
- Begin
- If TryStrToFloat(EditB.Text, Value) Then
- Begin
- If (Value < 0) Then
- Begin
- BalloonHint1.Title := 'Неверное значение.';
- BalloonHint1.Description := 'N должно быть больше 0.';
- BalloonHint1.ImageIndex := 1;
- BalloonHint1.ShowHint(EditB);
- EditB.Text := '';
- End;
- End;
- EditB.MaxLength := 5;
- If Length(EditB.Text) = 0 Then
- Begin
- Result.Lines.Clear;
- End;
- End;
- Procedure TMainForm.EditBContextPopup(Sender: TObject; MousePos: TPoint; Var Handled: Boolean);
- Begin
- Handled := True;
- End;
- Procedure TMainForm.EditBKeyPress(Sender: TObject; Var Key: Char);
- Begin
- If Key In NumSet Then
- Begin
- If Key = '0' Then
- Begin
- If Length(EditB.Text) = 1 Then
- Begin
- If EditB.Text[1] In ['0'] Then
- Begin
- Key := #0;
- End;
- End;
- If Length(EditB.Text) = 2 Then
- Begin
- If (EditB.Text[1] = '-') AND (EditB.Text[2] = '0') Then
- Begin
- Key := #0;
- End;
- End;
- End;
- If Key = #45 Then
- Begin
- If Length(EditB.Text) > 0 Then
- Begin
- BalloonHint1.Title := 'Недопустимый символ.';
- BalloonHint1.Description := 'Здесь можно ввести только число.';
- BalloonHint1.ShowHint(EditB);
- Key := #0;
- End;
- End;
- If Key In [',', '.'] Then
- Begin
- Key := FormatSettings.DecimalSeparator;
- If Pos(Key, EditB.Text) <> 0 Then
- Begin
- BalloonHint1.Title := 'Недопустимый символ.';
- BalloonHint1.Description := 'Здесь можно ввести только число.';
- BalloonHint1.ImageIndex := 1;
- BalloonHint1.ShowHint(EditB);
- Key := #0;
- End
- Else
- If Length(EditB.Text) > 0 Then
- Begin
- If (EditB.Text[1] = '-') AND (Length(EditB.Text) = 1) Then
- Begin
- Key := #0;
- End
- End
- Else
- If EditB.SelStart = 0 Then
- Begin
- EditB.Text := '0' + EditB.Text;
- EditB.SelStart := 1;
- End;
- End;
- End
- Else
- Begin
- BalloonHint1.Title := 'Недопустимый символ.';
- BalloonHint1.Description := 'Здесь можно ввести только число.';
- BalloonHint1.ImageIndex := 1;
- BalloonHint1.ShowHint(EditB);
- Key := #0;
- End;
- End;
- Procedure TMainForm.FormCloseQuery(Sender: TObject; Var CanClose: Boolean);
- Var
- Confirmation: Integer;
- Begin
- Confirmation := Application.MessageBox('Вы действительно хотите выйти?', 'Выход', MB_YESNO);
- CanClose := Confirmation = IDYES;
- End;
- Procedure TMainForm.FormMouseMove(Sender: TObject; Shift: TShiftState; X, Y: Integer);
- Begin
- If (EditA.Text <> '') And (EditB.Text <> '') Then
- Button1.Enabled := True
- Else
- Button1.Enabled := False;
- End;
- Procedure TMainForm.EditAChange(Sender: TObject);
- Var
- Value: Double;
- Begin
- If TryStrToFloat(EditA.Text, Value) Then
- Begin
- If (Value < 1) Then
- Begin
- BalloonHint1.Title := 'Неверное значение.';
- BalloonHint1.Description := 'N должно быть больше 0.';
- BalloonHint1.ImageIndex := 1;
- BalloonHint1.ShowHint(EditA);
- EditA.Text := '';
- End;
- End;
- EditA.MaxLength := 5;
- If Length(EditA.Text) = 0 Then
- Begin
- Result.Lines.Clear;
- End;
- End;
- Procedure TMainForm.EditAContextPopup(Sender: TObject; MousePos: TPoint; Var Handled: Boolean);
- Begin
- Handled := True;
- End;
- Procedure TMainForm.EditAKeyPress(Sender: TObject; Var Key: Char);
- Begin
- If Key In NumSet Then
- Begin
- If Key = '0' Then
- Begin
- If Length(EditA.Text) = 1 Then
- Begin
- If EditA.Text[1] In ['0'] Then
- Begin
- Key := #0;
- End;
- End;
- If Length(EditA.Text) = 2 Then
- Begin
- If (EditA.Text[1] = '-') AND (EditA.Text[2] = '0') Then
- Begin
- Key := #0;
- End;
- End;
- End;
- If Key = #45 Then
- Begin
- If Length(EditA.Text) > 0 Then
- Begin
- BalloonHint1.Title := 'Недопустимый символ.';
- BalloonHint1.Description := 'Здесь можно ввести только число.';
- BalloonHint1.ImageIndex := 1;
- BalloonHint1.ShowHint(EditA);
- Key := #0;
- End;
- End;
- If Key In [',', '.'] Then
- Begin
- Key := FormatSettings.DecimalSeparator;
- If Pos(Key, EditA.Text) <> 0 Then
- Begin
- BalloonHint1.Title := 'Недопустимый символ.';
- BalloonHint1.Description := 'Здесь можно ввести только число.';
- BalloonHint1.ImageIndex := 1;
- BalloonHint1.ShowHint(EditA);
- Key := #0;
- End
- Else
- If Length(EditA.Text) > 0 Then
- Begin
- If (EditA.Text[1] = '-') AND (Length(EditA.Text) = 1) Then
- Begin
- Key := #0;
- End
- End
- Else
- If EditA.SelStart = 0 Then
- Begin
- EditA.Text := '0' + EditA.Text;
- EditA.SelStart := 1;
- End;
- End;
- End
- Else
- Begin
- BalloonHint1.Title := 'Недопустимый символ.';
- BalloonHint1.Description := 'Здесь можно ввести только число.';
- BalloonHint1.ImageIndex := 1;
- BalloonHint1.ShowHint(EditA);
- Key := #0;
- End;
- End;
- Procedure TMainForm.N1Click(Sender: TObject);
- Begin
- If Result.Lines.Count = 0 Then
- Begin
- N4.Enabled := False;
- End
- Else
- Begin
- N4.Enabled := True;
- End;
- End;
- Procedure TMainForm.N2Click(Sender: TObject);
- Begin
- InstructionForm.ShowModal;
- End;
- Procedure TMainForm.GetPath(Var Path: String);
- Begin
- If OpenDialog1.Execute Then
- Begin
- Path := OpenDialog1.FileName;
- End
- Else
- Begin
- ShowMessage('Открытие файла отменено!');
- End;
- End;
- procedure TMainForm.N3Click(Sender: TObject);
- var
- IsCorrect, Fail: Boolean;
- Path, A, B, Str: String;
- Count: Integer;
- FileElem: TextFile;
- begin
- GetPath(Path);
- AssignFile(FileElem, Path);
- Fail := False;
- IsCorrect := True;
- Count := 0;
- if not FileExists(Path) then
- begin
- ShowMessage('Файл не найден!');
- Exit;
- end;
- try
- try
- Reset(FileElem);
- except
- CloseFile(FileElem);
- IsCorrect := False;
- ShowMessage('Ошибка открытия файла.');
- end;
- if IsCorrect then
- begin
- while not Eof(FileElem) do
- begin
- ReadLn(FileElem, Str);
- Inc(Count);
- end;
- CloseFile(FileElem);
- if Count <> 2 then
- Fail := True;
- end;
- if IsCorrect then
- begin
- Reset(FileElem);
- try
- Readln(FileElem, A);
- if not TryStrToInt(A, Count) then
- Fail := True;
- except
- Fail := True;
- end;
- try
- Readln(FileElem, B);
- if not TryStrToInt(B, Count) then
- Fail := True;
- except
- Fail := True;
- end;
- end;
- finally
- CloseFile(FileElem);
- if Fail then
- ShowMessage('Проверьте введенные данные и повторите попытку!')
- else
- begin
- EditA.Text := A;
- EditB.Text := B;
- end;
- ShowMessage('Обработка завершена.');
- end;
- end;
- Procedure TMainForm.N4Click(Sender: TObject);
- Begin
- If SaveDialog1.Execute Then
- Begin
- Result.Lines.SaveToFile(SaveDialog1.FileName);
- End
- Else
- Begin
- ShowMessage('Сохранение в файл отменено.');
- End;
- End;
- Procedure TMainForm.N5Click(Sender: TObject);
- Begin
- InformationForm.ShowModal;
- End;
- End.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement