unit fmMain;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, Menus, StdCtrls, uMyActions;

type
  TForm1 = class(TForm)
    Button1: TButton;
    MainMenu1: TMainMenu;
    est1: TMenuItem;
    SearchFile1: TMenuItem;
    FileInfo1: TMenuItem;
    Button2: TButton;
    Edit1: TEdit;
    Edit2: TEdit;
    Memo1: TMemo;
    Button3: TButton;
    Memo2: TMemo;
    procedure Button1Click(Sender: TObject);
    procedure SearchFile1Click(Sender: TObject);
    procedure Button2Click(Sender: TObject);
    procedure Button3Click(Sender: TObject);
  private
    { Private declarations }
    ltFileInfo : TStringList;
    myAction : TFileSearchAction;
    myFIAction : TFileInfoAction;
    myMacroAction : TFileMacroAction;
    procedure DoGetFileInfo(Sender: TObject; const sFile: string);
    procedure DoSearchFile(Sender : TObject);
  public
    { Public declarations }
    //IFileAction
    Constructor Create(AOwnder : TComponent); override;
    Destructor Destroy; override;
  end;

var
  Form1: TForm1;

implementation

{$R *.dfm}

{ TForm1 }

constructor TForm1.Create(AOwnder: TComponent);
begin
  inherited;
end;

destructor TForm1.Destroy;
begin
  if (Assigned(myAction)) then
    FreeAndNil(myAction);
  if (Assigned(myFIAction)) then
    FreeAndNil(myFIAction);
  if (Assigned(myMacroAction)) then
    FreeAndNil(myMacroAction);
  inherited;
end;

procedure TForm1.Button1Click(Sender: TObject);
begin
  DoSearchFile(Button1);
end;

procedure TForm1.SearchFile1Click(Sender: TObject);
begin
  DoSearchFile(SearchFile1);
end;

procedure TForm1.DoSearchFile(Sender : TObject);
begin
  if (myAction = nil) then
    myAction := TFileSearchAction.Create(Self);

  myAction.FileName := Self.Edit1.Text;
  myAction.Execute;
  Self.Edit2.Text := myAction.FileName;
  Memo1.Lines.Assign(myAction.FoundFiles);
end;

procedure TForm1.Button2Click(Sender: TObject);
begin
  DoGetFileInfo(Button2, Self.Edit1.Text);
end;

procedure TForm1.DoGetFileInfo(Sender: TObject; const sFile: string);
begin
  if (myFIAction = nil) then
    myFIAction := TFileInfoAction.Create(Self);
  myFIAction.FileName := Self.Edit1.Text;
  myFIAction.Execute;
  Memo1.Lines.Assign(myFIAction.FileInfo);
end;

procedure TForm1.Button3Click(Sender: TObject);
begin
  if (myMacroAction = nil) then
    myMacroAction := TFileMacroAction.Create(Self);
  myMacroAction.FileName := Self.Edit1.Text;
  myMacroAction.Execute;
  Memo2.Lines.Assign(myMacroAction.FileMacroInfo);
end;

end.
