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.Menus;
- type
- TForm1 = class(TForm)
- Label1: TLabel;
- Label2: TLabel;
- Edit1: TEdit;
- Button1: TButton;
- Label3: TLabel;
- Label4: TLabel;
- MainMenu1: TMainMenu;
- PopupMenu1: TPopupMenu;
- SaveDialog1: TSaveDialog;
- OpenDialog1: TOpenDialog;
- N1: TMenuItem;
- N2: TMenuItem;
- N3: TMenuItem;
- N4: TMenuItem;
- N5: TMenuItem;
- procedure Button1Click(Sender: TObject);
- procedure Edit1Change(Sender: TObject);
- procedure Edit1KeyPress(Sender: TObject; var Key: Char);
- procedure N4Click(Sender: TObject);
- procedure N2Click(Sender: TObject);
- procedure N3Click(Sender: TObject);
- procedure N5Click(Sender: TObject);
- procedure FormCloseQuery(Sender: TObject; var CanClose: Boolean);
- private
- { Private declarations }
- public
- { Public declarations }
- end;
- var
- Form1: TForm1;
- Result, Condition, Path : String;
- IsFileOpen : Boolean;
- Const
- OK = ['a'..'z','A'..'Z', #08, #46, #32];
- implementation
- {$R *.dfm}
- procedure TForm1.Button1Click(Sender: TObject);
- var
- Str, TempStr : String;
- I, J, Counter, LastOne : Integer;
- ArrOfStr : Array of String[2];
- ArrOFCounters : Array Of Integer;
- Flag : Boolean;
- Const
- OK = ['a' .. 'z'];
- begin
- Label3.Caption := '';
- Flag := True;
- Str := Edit1.Text;
- Condition := 'Исходная строка: ' + Str + #13#10;
- SetLength(ArrOfStr, Str.Length - 1);
- SetLength(ArrOFCounters, Str.Length - 1);
- For J := 0 To High(ArrOFCounters) Do
- ArrOFCounters[J] := 1;
- I := 1;
- While I <> Str.Length Do
- Begin
- If (Str[I] = ' ') then
- Begin
- Delete(Str, I, 1);
- Dec(I);
- End;
- Inc(I);
- End;
- I := 0;
- While I <> Str.Length - 1 Do
- Begin
- TempStr := Str.Substring(I, 2);
- For J := 0 To High(ArrOfStr) Do
- If (TempStr = ArrofStr[J]) and (ArrOfStr[J] <> '') then
- Begin
- Inc(ArrOFCounters[J]);
- Flag := False;
- End
- else
- begin
- If (ArrOFStr[J] = '') and (Flag) then
- Begin
- ArrOfStr[J] := TempStr;
- Break
- End;
- end;
- Flag := True;
- Inc(I);
- End;
- For I := 0 To High(ArrOfStr) Do
- If ArrOfStr[I] = '' then
- SetLength(ArrOfStr, High(ArrOfStr));
- Counter := 0;
- For J := 0 To High (ArrOfStr) Do
- Begin
- Label3.Caption := Label3.Caption + ArrOfStr[J] + ' - ' + IntToStr(ArrOfCounters[J]) + ' раз(а); ';
- Inc(Counter);
- If Counter mod 6 = 0 then
- Label3.Caption := Label3.Caption + #13#10;
- End;
- Result := 'Результат: ' + Label3.Caption;
- N3.Enabled := True;
- end;
- procedure TForm1.Edit1Change(Sender: TObject);
- begin
- Label3.Caption := '';
- If (Length (Edit1.Text) = 0) or (Length (Edit1.Text) = 1)then
- Button1.Enabled := False
- else
- begin
- Button1.Enabled := True;
- end;
- N3.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 OK)) Then
- Key := #0;
- If Key = '.' then
- Key := #0;
- end;
- procedure TForm1.FormCloseQuery(Sender: TObject; var CanClose: Boolean);
- begin
- CanClose := MessageBox(Form1.Handle, 'Вы уверены, что хотите выйти?', 'Выход', MB_YESNO + MB_ICONQUESTION)=ID_YES;
- end;
- procedure TForm1.N4Click(Sender: TObject);
- begin
- Application.MessageBox('Максимальная длина исходной строки: 108 символов.'#13#10'Можно вводить только текст на латинице.', 'Инструкция', 0);
- end;
- procedure TForm1.N5Click(Sender: TObject);
- begin
- Application.MessageBox('Арефин Владислав гр.251004', 'Разрабочик', 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 CheckStr (Str : String) : String;
- Var
- I : Integer;
- IsCorrect : Boolean;
- FileInput: TextFile;
- Begin
- IsCorrect := True;
- Path := Open;
- AssignFile(FileInput, Path);
- Reset(FileInput);
- If(IsFileOpen) Then
- Begin
- Readln(FileInput, Str);
- End;
- CloseFile(FileInput);
- For I := 1 To Str.Length Do
- If (Not(Str[I] in OK)) and (IsCorrect) then
- IsCorrect := False;
- If Length(Str) > 108 then
- begin
- IsCorrect := False;
- end;
- If IsCorrect then
- CheckStr := Str
- else
- CheckStr := '';
- End;
- procedure TForm1.N2Click(Sender: TObject);
- Var
- Str : String;
- begin
- Str := CheckStr(Str);
- If Str <> '' then
- begin
- Edit1.Text := Str;
- end
- else
- begin
- MessageBox(Form1.Handle, Pchar('Проверьте исходные данные. Текст должен быть написан только латиницей, не содержать цифр и специальных знаков. Максимальная длина - 108 символов.'), 'Ошибка', MB_ICONSTOP);
- end;
- end;
- procedure TForm1.N3Click(Sender: TObject);
- Var
- FileOutput: TextFile;
- IsCorrect : Boolean;
- ForSave : String;
- begin
- ForSave := Condition + Result;
- IsCorrect := True;
- Path := Open;
- If (IsFileOpen) Then
- Begin
- try
- AssignFile(FileOutput, Path);
- Rewrite(FileOutput);
- Write(FileOutput, ForSave);
- except
- IsCorrect := False;
- Application.MessageBox('Запись в файл не удалась.', 'Ошибка', MB_ICONSTOP);
- end;
- if IsCorrect then
- Begin
- Application.MessageBox('Запись файла выполнена успешно.', 'Результат', 0);
- Edit1.Text := '';
- Label3.Caption := '';
- CloseFile(FileOutput);
- End;
- End;
- end;
- end.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement