Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- unit Lab_3_1;
- 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
- TForm1 = class(TForm)
- MainMenu: TMainMenu;
- Label1: TLabel;
- EditFirstString: TEdit;
- EditSecString: TEdit;
- Button1: TButton;
- Button2: TButton;
- Button3: TButton;
- Label2: TLabel;
- Label3: TLabel;
- Label4: TLabel;
- N1: TMenuItem;
- N2: TMenuItem;
- N3: TMenuItem;
- N4: TMenuItem;
- N5: TMenuItem;
- OpenDialog: TOpenDialog;
- SaveDialog: TSaveDialog;
- EditAnswer: TEdit;
- procedure N4Click(Sender: TObject);
- procedure N5Click(Sender: TObject);
- procedure EditFirstStringChange(Sender: TObject);
- procedure EditSecStringChange(Sender: TObject);
- procedure Button1Click(Sender: TObject);
- procedure Button2Click(Sender: TObject);
- procedure Button3Click(Sender: TObject);
- procedure FormCreate(Sender: TObject);
- private
- { Private declarations }
- public
- { Public declarations }
- end;
- var
- Form1: TForm1;
- implementation
- {$R *.dfm}
- uses UnitError;
- Var
- FirstString, SecString, Answer: String;
- Procedure FindIntersectionOfStrings(FirstStr, SecoStr: String; Var Ans: String);
- Var
- I: Integer;
- Begin
- Ans := '';
- For I := 1 To Length(FirstString) Do
- If Pos(FirstString[I], SecString) <> 0 Then
- Ans := Ans + FirstString[I];
- End;
- Procedure FindSpecialCharInString(FirstStr, SecStr: String; Var Ans: String);
- Var
- I: Integer;
- Begin
- Ans := '';
- For I := 1 To Length(FirstStr) Do
- If Pos(FirstStr[I], SecStr) = 0 Then
- Ans := Ans + FirstStr[I];
- End;
- procedure TForm1.Button1Click(Sender: TObject);
- begin
- FindIntersectionOfStrings(FirstString, SecString, Answer);
- If Answer = '' Then
- EditAnswer.Text := 'В строке не найдено искомых элементов'
- Else
- EditAnswer.Text := Answer;
- end;
- procedure TForm1.Button2Click(Sender: TObject);
- begin
- FindSpecialCharInString(FirstString, SecString, Answer);
- EditAnswer.Text := Answer;
- end;
- procedure TForm1.Button3Click(Sender: TObject);
- begin
- FindSpecialCharInString(SecString, FirstString, Answer);
- EditAnswer.Text := Answer;
- end;
- procedure TForm1.EditFirstStringChange(Sender: TObject);
- begin
- If (EditSecString.Text <> '') Then
- Begin
- Button1.Enabled := True;
- Button2.Enabled := True;
- Button3.Enabled := True;
- End;
- EditSecString.Enabled := True;
- N5.Enabled := False;
- EditAnswer.Text := '';
- Answer := '';
- If (EditFirstString.Text = '') Then
- Begin
- N5.Enabled := False;
- Button1.Enabled := False;
- Button2.Enabled := False;
- Button3.Enabled := False;
- EditSecString.Enabled := False;
- FirstString := '';
- End
- Else
- FirstString := FirstString + EditFirstString.Text;
- end;
- procedure TForm1.EditSecStringChange(Sender: TObject);
- begin
- Button1.Enabled := True;
- Button2.Enabled := True;
- Button3.Enabled := True;
- EditAnswer.Text := '';
- If (EditSecString.Text = '') Then
- Begin
- N5.Enabled := False;
- Button1.Enabled := False;
- Button2.Enabled := False;
- Button3.Enabled := False;
- SecString := '';
- End
- Else
- SecString := SecString + EditSecString.Text;
- end;
- procedure TForm1.FormCreate(Sender: TObject);
- begin
- FirstString := '';
- SecString := '';
- end;
- procedure TForm1.N4Click(Sender: TObject);
- var
- F: TextFile;
- Path, EOF_Error: String;
- Res: Integer;
- IsCorrect: Boolean;
- begin
- Res := 0;
- IsCorrect := True;
- EOF_Error := '';
- If OpenDialog.Execute() Then
- Begin
- Path := OpenDialog.FileName;
- AssignFile(F, Path);
- Try
- Reset(F);
- Try
- Readln(F, FirstString);
- Readln(F, SecString);
- If Not EOF(F) Then
- Begin
- EOF_Error := 'В файле найдены лишние элементы';
- IsCorrect := False;
- End
- Else
- Begin
- EditFirstString.Text := UTF8ToAnsi(FirstString);
- EditSecString.Text := UTF8ToAnsi(SecString);
- End;
- Finally
- CloseFile(F);
- End;
- Except
- IsCorrect := False;
- End;
- If not (IsCorrect) Then
- Begin
- UnitError.FormError.LabelError.Caption := 'Ошибка считывания с файла. ' + EOF_Error;
- Res := UnitError.FormError.ShowModal();
- End;
- if Res > 0 Then
- UnitError.FormError.LabelError.Caption := '';
- End;
- end;
- procedure TForm1.N5Click(Sender: TObject);
- Var
- F: TextFile;
- Path: String;
- Res: Integer;
- begin
- Res := 0;
- If SaveDialog.Execute() Then
- Begin
- Path := SaveDialog.FileName;
- AssignFile(F, Path);
- Try
- Rewrite(F);
- Try
- Write(F, EditAnswer.Text);
- Finally
- CloseFile(F);
- End;
- Except
- UnitError.FormError.LabelError.Caption := 'Ошибка записи в файл.';
- Res := UnitError.FormError.ShowModal();
- End;
- If (Res > 0) Then
- UnitError.FormError.LabelError.Caption := '';
- End;
- end;
- end.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement