Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- unit LabForm1_3;
- interface
- uses
- Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants, System.Classes, Vcl.Graphics,
- Vcl.Controls, Vcl.Forms, Vcl.Dialogs, Vcl.StdCtrls, Vcl.Menus;
- type
- TMainForm = class(TForm)
- InputNumber: TEdit;
- SaveDialog: TSaveDialog;
- OpenDialog: TOpenDialog;
- MainMenu: TMainMenu;
- FileMenu: TMenuItem;
- OpenFile: TMenuItem;
- SaveInFile: TMenuItem;
- CalculateButton: TButton;
- Label1: TLabel;
- Label2: TLabel;
- OutputLabel: TLabel;
- Procedure FindAmount(Number: Double);
- procedure FileMenuClick(Sender: TObject);
- procedure CalculateButtonClick(Sender: TObject);
- procedure OpenFileClick(Sender: TObject);
- procedure SaveInFileClick(Sender: TObject);
- procedure InputChange(Sender: TObject);
- procedure FormCloseQuery(Sender: TObject; var CanClose: Boolean);
- private
- { Private declarations }
- public
- { Public declarations }
- end;
- var
- MainForm: TMainForm;
- implementation
- {$R *.dfm}
- Procedure TMainForm.FindAmount(Number: Double);
- Var
- ColOfNumber, I: Integer;
- Begin
- If Number = 0 then
- ColOfNumber := 1;
- While (Number >= 1) do
- Begin
- Number := Number / 10;
- ColOfNumber := ColOfNumber + 1;
- End;
- Outputlabel.Caption := 'Количество цифр: ' + IntToStr(ColOfNumber);
- End;
- procedure TMainForm.InputChange(Sender: TObject);
- begin
- OutputLabel.Caption := '';
- MainForm.Height := MainForm.Height - 30;
- end;
- procedure TMainForm.CalculateButtonClick(Sender: TObject);
- Var
- IsCorrect: Boolean;
- begin
- IsCorrect := True;
- if (IsCorrect = true) then
- Begin
- Try
- FindAmount(StrToInt(InputNumber.Text));
- MainForm.Height := MainForm.Height + 30;
- Except
- MessageDlg('Введите натуральное число', mtError, [mbOk], 0);
- End;
- End;
- end;
- function CheckFile(Path: String): Boolean;
- var
- FileToCheck: TextFile;
- N: Integer;
- begin
- AssignFile(FileToCheck, Path);
- Reset(FileToCheck);
- CheckFile := true;
- try
- Readln(FileToCheck, N);
- except
- CheckFile := false;
- end;
- CloseFile(FileToCheck);
- end;
- procedure TMainForm.OpenFileClick(Sender: TObject);
- var
- InputFile: TextFile;
- N: Integer;
- IsCorrect: Boolean;
- begin
- if OpenDialog.Execute then
- begin
- IsCorrect := true;
- if CheckFile(OpenDialog.FileName) then
- begin
- AssignFile(InputFile, OpenDialog.FileName);
- Reset(InputFile);
- Read(InputFile, N);
- InputNumber.Text := IntToStr(N);
- CloseFile(InputFile);
- ShowMessage('Данные из файла успешно загружены');
- end
- else
- Begin
- ShowMessage('Данные в файле некорректны');
- IsCorrect := false;
- End;
- if (IsCorrect = true) then
- Begin
- MainForm.Height := MainForm.Height + 30;
- Try
- FindAmount(StrToInt(InputNumber.Text));
- Except
- MessageDlg('Введите натуральное число', mtError, [mbOk], 0);
- End;
- End;
- end;
- end;
- procedure TMainForm.SaveInFileClick(Sender: TObject);
- var
- OutputFile: TextFile;
- begin
- if SaveDialog.Execute then
- begin
- AssignFile(OutputFile, SaveDialog.FileName);
- Rewrite(OutputFile);
- writeln(OutputFile, 'Число : ' + InputNumber.Text);
- Write(OutputFile, MainForm.OutputLabel.Caption);
- CloseFile(OutputFile);
- ShowMessage('Успешно сохранено');
- end;
- end;
- procedure TMainForm.FileMenuClick(Sender: TObject);
- begin
- SaveInFile.Enabled := Not (OutputLabel.Caption = '');
- end;
- procedure TMainForm.FormCloseQuery(Sender: TObject; var CanClose: Boolean);
- begin
- CanClose := MessageDlg('Вы уверены, что хотите выйти из программы?' +
- #10#13 + 'Все несохранённые данные будут утеряны.',
- mtConfirmation, [mbYes, mbNo], 0) = mrYes;
- end;
- end.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement