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.Menus, Vcl.StdCtrls;
- Type
- TSet = Set Of Char;
- TForm1 = Class(TForm)
- MainMenu1: TMainMenu;
- N1: TMenuItem;
- N2: TMenuItem;
- N3: TMenuItem;
- N4: TMenuItem;
- Task: TLabel;
- InputStringLabel: TLabel;
- EditInputString: TEdit;
- ReceivedSetLabel: TLabel;
- EditOutputSet: TEdit;
- ButtonFindElements: TButton;
- OpenDialog1: TOpenDialog;
- SaveDialog1: TSaveDialog;
- procedure ButtonFindElementsClick(Sender: TObject);
- procedure EditInputStringChange(Sender: TObject);
- procedure EditInputStringKeyPress(Sender: TObject; var Key: Char);
- procedure N1Click(Sender: TObject);
- procedure N2Click(Sender: TObject);
- procedure FormCloseQuery(Sender: TObject; var CanClose: Boolean);
- procedure N3Click(Sender: TObject);
- procedure N4Click(Sender: TObject);
- Private
- { Private declarations }
- Public
- { Public declarations }
- End;
- Var
- Form1: TForm1;
- Sequence: AnsiString;
- Implementation
- {$R *.dfm}
- uses Unit3, Unit2, Unit4;
- Function GetSearchСharactersSet(Sequence: AnsiString): TSet;
- Const
- SearchCharacters = [#40, #41, #91, #93, #123, #125, #48..#57];
- Var
- SearchSet: TSet;
- I: Integer;
- Begin
- SearchSet := [];
- For I := 1 To Length(Sequence) Do
- If Sequence[I] In SearchCharacters Then
- Include(SearchSet, Sequence[I]);
- GetSearchСharactersSet := SearchSet;
- End;
- Procedure TForm1.ButtonFindElementsClick(Sender: TObject);
- Var
- SearchSet: TSet;
- I: Integer;
- Begin
- SearchSet := GetSearchСharactersSet(Sequence);
- If SearchSet <> [] Then
- Begin
- For I := 0 To 255 Do
- If Chr(I) In SearchSet Then
- EditOutputSet.Text := EditOutputSet.Text + Chr(I) + ' ';
- End
- Else
- EditOutputSet.Text := 'В строке не было найдено скобок и цифр.';
- ButtonFindElements.Enabled := False;
- N2.Enabled := True;
- End;
- procedure TForm1.EditInputStringChange(Sender: TObject);
- begin
- ButtonFindElements.Enabled := True;
- N2.Enabled := False;
- EditOutputSet.Text := '';
- If (EditInputString.Text = '') Then
- Begin
- N2.Enabled := False;
- ButtonFindElements.Enabled := False;
- Sequence := '';
- End
- Else
- Sequence := Sequence + EditInputString.Text;
- end;
- procedure TForm1.EditInputStringKeyPress(Sender: TObject; var Key: Char);
- begin
- If Key = #13 Then
- ButtonFindElementsClick(Sender);
- end;
- procedure TForm1.FormCloseQuery(Sender: TObject; var CanClose: Boolean);
- Var
- Res: Integer;
- begin
- Res := Unit2.Form2.ShowModal();
- If Res = mrOk Then
- CanClose := True
- Else
- CanClose := False;
- end;
- procedure TForm1.N1Click(Sender: TObject);
- var
- F: TextFile;
- Path: String;
- begin
- If OpenDialog1.Execute() Then
- Begin
- Path := OpenDialog1.FileName;
- AssignFile(F, Path);
- Try
- Reset(F);
- Try
- Readln(F, Sequence);
- EditInputString.Text := Sequence;
- Finally
- CloseFile(F);
- End;
- Except
- EditInputString.Text := 'Ошибка считывания с файла';
- End;
- End;
- end;
- procedure TForm1.N2Click(Sender: TObject);
- Var
- F: TextFile;
- Path: String;
- begin
- If SaveDialog1.Execute() Then
- Begin
- Path := SaveDialog1.FileName;
- AssignFile(F, Path);
- Try
- Rewrite(F);
- Try
- Write(F, EditOutputSet.Text);
- Finally
- CloseFile(F);
- End;
- Except
- EditOutputSet.Text := 'Ошибка записи в файл';
- End;
- End;
- end;
- procedure TForm1.N3Click(Sender: TObject);
- begin
- Unit3.Form3.ShowModal();
- end;
- procedure TForm1.N4Click(Sender: TObject);
- begin
- Unit4.Form4.ShowModal();
- end;
- End.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement