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,
- Vcl.Controls,
- Vcl.Forms,
- Vcl.Dialogs,
- Vcl.StdCtrls,
- Vcl.Menus,
- Vcl.ExtCtrls,
- Vcl.Imaging.Pngimage,
- System.Actions,
- Vcl.ActnList;
- Type
- TMainForm = Class(TForm)
- ResButton: TButton;
- EditKoefX: TEdit;
- EditKoefY: TEdit;
- MainMenu1: TMainMenu;
- FileTab: TMenuItem;
- InstructionTab: TMenuItem;
- OpenOption: TMenuItem;
- SaveOption: TMenuItem;
- DeveloperTab: TMenuItem;
- BalloonHint1: TBalloonHint;
- OpenDialog1: TOpenDialog;
- SaveDialog1: TSaveDialog;
- MemoRes: TMemo;
- ActionList1: TActionList;
- Action1: TAction;
- KoefXLabel: TLabel;
- KoefYLabel: TLabel;
- TaskImage: TImage;
- Procedure ResButtonClick(Sender: TObject);
- Procedure InstructionTabClick(Sender: TObject);
- Procedure DeveloperTabClick(Sender: TObject);
- Procedure EditKoefYKeyPress(Sender: TObject; Var Key: Char);
- Procedure EditKoefXKeyPress(Sender: TObject; Var Key: Char);
- Procedure OpenOptionClick(Sender: TObject);
- Procedure GetPath(Var Path: String);
- Procedure SaveOptionClick(Sender: TObject);
- Procedure Checker(Var IsCorrect: Boolean);
- Procedure FileTabClick(Sender: TObject);
- Procedure EditKoefXChange(Sender: TObject);
- Procedure EditKoefYChange(Sender: TObject);
- Procedure Action1Update(Sender: TObject);
- Procedure FormCloseQuery(Sender: TObject; Var CanClose: 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;
- KoefX, KoefY: Double;
- Implementation
- {$R *.dfm}
- Uses
- Instruction,
- Information;
- Procedure TMainForm.Checker(Var IsCorrect: Boolean);
- Begin
- IsCorrect := True;
- Try
- StrtoFloat(EditKoefX.Text);
- Except
- IsCorrect := False;
- End;
- Try
- StrtoFloat(EditKoefY.Text);
- Except
- IsCorrect := False;
- End;
- End;
- Procedure TMainForm.Action1Update(Sender: TObject);
- Begin
- TAction(Sender).Enabled := (EditKoefX.Text <> '') And (EditKoefY.Text <> '')
- End;
- Procedure TMainForm.ResButtonClick(Sender: TObject);
- Var
- IsCorrect: Boolean;
- Begin
- Checker(IsCorrect);
- If IsCorrect Then
- Begin
- KoefX := StrtoFloat(EditKoefX.Text);
- KoefY := StrtoFloat(EditKoefY.Text);
- If (KoefY + KoefX <= 1) And (2 * KoefX - KoefY <= 1) And (KoefY >= 0) Then
- Begin
- MemoRes.Lines.Add('Точка M (' + EditKoefX.Text + ';' + EditKoefY.Text + ') принадлежит замкнутому множеству D');
- End
- Else
- Begin
- MemoRes.Lines.Add('Точка M (' + EditKoefX.Text + ';' + EditKoefY.Text + ') не принадлежит замкнутому множеству D');
- End;
- End;
- End;
- Procedure TMainForm.EditKoefYChange(Sender: TObject);
- Begin
- If Length(EditKoefY.Text) = 0 Then
- Begin
- MemoRes.Lines.Clear;
- End;
- End;
- Procedure TMainForm.EditKoefYKeyPress(Sender: TObject; Var Key: Char);
- Begin
- If Key In NumSet Then
- Begin
- If Key = '0' Then
- Begin
- If Length(EditKoefY.Text) = 1 Then
- Begin
- If EditKoefY.Text[1] In ['0'] Then
- Begin
- Key := #0;
- End;
- End;
- If Length(EditKoefY.Text) = 2 Then
- Begin
- If (EditKoefY.Text[1] = '-') AND (EditKoefY.Text[2] = '0') Then
- Begin
- Key := #0;
- End;
- End;
- End;
- If Key = #45 Then
- Begin
- If Length(EditKoefY.Text) > 0 Then
- Begin
- BalloonHint1.Title := 'Недопустимый символ.';
- BalloonHint1.Description := 'Здесь можно ввести только число.';
- BalloonHint1.ImageIndex := 1;
- BalloonHint1.ShowHint(EditKoefY);
- Key := #0;
- End;
- End;
- If Key In [',', '.'] Then
- Begin
- Key := FormatSettings.DecimalSeparator;
- If Pos(Key, EditKoefY.Text) <> 0 Then
- Begin
- BalloonHint1.Title := 'Недопустимый символ.';
- BalloonHint1.Description := 'Здесь можно ввести только число.';
- BalloonHint1.ImageIndex := 1;
- BalloonHint1.ShowHint(EditKoefY);
- Key := #0;
- End
- Else
- If Length(EditKoefY.Text) > 0 Then
- Begin
- If (EditKoefY.Text[1] = '-') AND (Length(EditKoefY.Text) = 1) Then
- Begin
- Key := #0;
- End
- End
- Else
- If EditKoefY.SelStart = 0 Then
- Begin
- EditKoefY.Text := '0' + EditKoefY.Text;
- EditKoefY.SelStart := 1;
- End;
- End;
- End
- Else
- Begin
- BalloonHint1.Title := 'Недопустимый символ.';
- BalloonHint1.Description := 'Здесь можно ввести только число.';
- BalloonHint1.ImageIndex := 1;
- BalloonHint1.ShowHint(EditKoefY);
- Key := #0;
- End;
- End;
- Procedure TMainForm.EditKoefXChange(Sender: TObject);
- Begin
- If Length(EditKoefX.Text) = 0 Then
- Begin
- MemoRes.Lines.Clear;
- End;
- End;
- Procedure TMainForm.EditKoefXKeyPress(Sender: TObject; Var Key: Char);
- Begin
- If Key In NumSet Then
- Begin
- If Key = '0' Then
- Begin
- If Length(EditKoefX.Text) = 1 Then
- Begin
- If EditKoefX.Text[1] In ['0'] Then
- Begin
- Key := #0;
- End;
- End;
- If Length(EditKoefX.Text) = 2 Then
- Begin
- If (EditKoefX.Text[1] = '-') AND (EditKoefX.Text[2] = '0') Then
- Begin
- Key := #0;
- End;
- End;
- End;
- If Key = #45 Then
- Begin
- If Length(EditKoefX.Text) > 0 Then
- Begin
- BalloonHint1.Title := 'Недопустимый символ.';
- BalloonHint1.Description := 'Здесь можно ввести только число.';
- BalloonHint1.ImageIndex := 1;
- BalloonHint1.ShowHint(EditKoefX);
- Key := #0;
- End;
- End;
- If Key In [',', '.'] Then
- Begin
- Key := FormatSettings.DecimalSeparator;
- If Pos(Key, EditKoefX.Text) <> 0 Then
- Begin
- BalloonHint1.Title := 'Недопустимый символ.';
- BalloonHint1.Description := 'Здесь можно ввести только число.';
- BalloonHint1.ImageIndex := 1;
- BalloonHint1.ShowHint(EditKoefX);
- Key := #0;
- End
- Else
- If Length(EditKoefX.Text) > 0 Then
- Begin
- If (EditKoefX.Text[1] = '-') AND (Length(EditKoefX.Text) = 1) Then
- Begin
- Key := #0;
- End
- End
- Else
- If EditKoefX.SelStart = 0 Then
- Begin
- EditKoefX.Text := '0' + EditKoefX.Text;
- EditKoefX.SelStart := 1;
- End;
- End;
- End
- Else
- Begin
- BalloonHint1.Title := 'Недопустимый символ.';
- BalloonHint1.Description := 'Здесь можно ввести только число.';
- BalloonHint1.ImageIndex := 1;
- BalloonHint1.ShowHint(EditKoefX);
- Key := #0;
- End;
- End;
- Procedure TMainForm.FileTabClick(Sender: TObject);
- Begin
- If MemoRes.Lines.Count = 0 Then
- Begin
- SaveOption.Enabled := False;
- End
- Else
- Begin
- SaveOption.Enabled := True;
- End;
- End;
- Procedure TMainForm.FormCloseQuery(Sender: TObject; Var CanClose: Boolean);
- Begin
- If MessageDlg('Вы уверены, что хотите выйти?', MtConfirmation, [MbYes, MbNo], 0) = MrYes Then
- CanClose := True
- Else
- CanClose := False;
- End;
- Procedure TMainForm.InstructionTabClick(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.OpenOptionClick(Sender: TObject);
- Var
- IsCorrect: Boolean;
- Path, Errors, KoefX, KoefY: String;
- FileElem: TextFile;
- Begin
- GetPath(Path);
- AssignFile(FileElem, Path);
- IsCorrect := True;
- Try
- Try
- Reset(FileElem);
- Except
- CloseFile(FileElem);
- IsCorrect := False;
- ShowMessage('Ошибка открытия файла.');
- End;
- If IsCorrect Then
- Begin
- Try
- Readln(FileElem, KoefX);
- StrtoFloat(KoefX);
- Except
- Errors := 'Для X было присвоено значение 1, т.к. на вход поступило некорректное значение.';
- KoefX := '1';
- End;
- Try
- Readln(FileElem, KoefY);
- StrtoFloat(KoefY);
- Except
- Errors := Errors + #13#10 + 'Для Y было присвоено значение 1, т.к. на вход поступило некорректное значение.';
- KoefY := '1';
- End;
- End;
- Finally
- CloseFile(FileElem);
- ShowMessage('Импорт завершен.');
- End;
- If Errors.Length > 0 Then
- Begin
- ShowMessage(Errors);
- End;
- EditKoefX.Text := KoefX;
- EditKoefY.Text := KoefY;
- End;
- Procedure TMainForm.SaveOptionClick(Sender: TObject);
- Begin
- If SaveDialog1.Execute Then
- Begin
- MemoRes.Lines.SaveToFile(SaveDialog1.FileName);
- End
- Else
- Begin
- ShowMessage('Сохранине в файл отменено.');
- End;
- End;
- Procedure TMainForm.DeveloperTabClick(Sender: TObject);
- Begin
- InformationForm.ShowModal;
- End;
- End.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement