unit UDlgChooseCommandTool;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls, UCommandInterface, UCmdTools;
type
TCommands =
class(TInterfacedObject, ICommandTool)
private
FCommands: TCmdTools;
public
constructor Create;
destructor Destroy;
override;
function GetCommand(
Index: Integer): TCmdTool;
function GetCount: Integer;
procedure AssignCommands(Commands: TCmdTools);
procedure RegisterCommand(
Name, Command:
String; Options:String='
'; CfgFile:String='
'; AOptionsFactory:TOptionsFactory=nil
);
procedure SetCommand(
Index: Integer; Value: TCmdTool);
property Command[
Index: Integer]: TCmdTool
read GetCommand;
property Count: Integer
read GetCount;
end;
TDlgChooseCommandTool =
class(TForm)
lbxChoosedCommandTool: TListBox;
cbxChoosedCommandTool: TComboBox;
lbRegisteredCommandTools: TLabel;
lbChoosedCommandTool: TLabel;
btnOk: TButton;
btnCancel: TButton;
btnHelp: TButton;
procedure FormCreate(Sender: TObject);
procedure lbxChoosedCommandToolClick(Sender: TObject);
procedure btnOkClick(Sender: TObject);
procedure FormDestroy(Sender: TObject);
private
{ Private declarations }
FCommands: TCommands;
FCurrentChoosed: Integer;
//FOptionsFactory: TComponent;
function GetChoosedIndex: Integer;
public
{ Public declarations }
procedure AssignCommands(Commands: TCmdTools);
property ChoosedIndex: Integer
read GetChoosedIndex;
end;
var
DlgChooseCommandTool: TDlgChooseCommandTool;
implementation
{$R *.dfm}
procedure TDlgChooseCommandTool.AssignCommands(Commands: TCmdTools);
var Index: Integer;
begin
if (Assigned(Commands))
and (Assigned(FCommands))
then
begin
FCommands.AssignCommands(Commands);
for Index := 0
to Commands.Count - 1
do
begin
cbxChoosedCommandTool.Items.Add(FCommands.Command[
Index].
Name);
lbxChoosedCommandTool.Items.Add(FCommands.Command[
Index].
Name);
end;
end;
end;
procedure TDlgChooseCommandTool.btnOkClick(Sender: TObject);
begin
GetChoosedIndex;
end;
procedure TDlgChooseCommandTool.FormCreate(Sender: TObject);
begin
FCommands := TCommands.Create;
end;
procedure TDlgChooseCommandTool.FormDestroy(Sender: TObject);
begin
if Assigned(FCommands)
then begin FCommands.Free; FCommands :=
nil;
end;
end;
function TDlgChooseCommandTool.GetChoosedIndex: Integer;
var Index: Integer;
begin
Result := -1;
while Index < lbxChoosedCommandTool.Items.Count
do
begin
if cbxChoosedCommandTool.Items[
Index] = cbxChoosedCommandTool.Text
then
begin
FCurrentChoosed :=
Index;
Result :=
Index;
Index := lbxChoosedCommandTool.Items.Count;
end;
Inc(
Index);
end;
end;
procedure TDlgChooseCommandTool.lbxChoosedCommandToolClick(Sender: TObject);
begin
cbxChoosedCommandTool.ItemIndex := lbxChoosedCommandTool.ItemIndex;
cbxChoosedCommandTool.Text := cbxChoosedCommandTool.Items[cbxChoosedCommandTool.ItemIndex];
end;
{ TCommands }
procedure TCommands.AssignCommands(Commands: TCmdTools);
begin
if Assigned(Commands)
then FCommands.Assign(Commands);
end;
constructor TCommands.Create;
begin
inherited Create;
FCommands := TCmdTools.Create;
end;
destructor TCommands.Destroy;
begin
FCommands.Free;
inherited;
end;
function TCommands.GetCommand(
Index: Integer): TCmdTool;
begin
if Assigned(FCommands)
then
Result := TCmdTool(FCommands[
Index])
else Result :=
nil;
end;
function TCommands.GetCount: Integer;
begin
Result := FCommands.Count;
end;
procedure TCommands.RegisterCommand(
Name, Command, Options, CfgFile:
String;
AOptionsFactory: TOptionsFactory);
begin
FCommands.AddCmdTool(RegisterCommandLineTool(
Name, Command, Options, CfgFile, AOptionsFactory));
end;
procedure TCommands.SetCommand(
Index: Integer; Value: TCmdTool);
begin
{
FCommands.CmdTool[Index].Name := Value.Name;
FCommands.CmdTool[Index].Command := Value.Command;
FCommands.CmdTool[Index].CfgFile := Value.CfgFile;
}
FCommands.CmdTool[
Index].Factory := Value.Factory;
end;
end.