65 lines
1.6 KiB
ObjectPascal
65 lines
1.6 KiB
ObjectPascal
unit commandcol;
|
|
|
|
{$mode ObjFPC}{$H+}
|
|
|
|
interface
|
|
|
|
uses
|
|
Classes, SysUtils,Contnrs,baseconnection;
|
|
type
|
|
{ TCommandCollection }
|
|
TCommandCollection=Class;
|
|
TCommandCollection=Class(TClassList)
|
|
private
|
|
class var fCollection: TCommandCollection;
|
|
public
|
|
class procedure Register(ACommand: TCommandClass);
|
|
class function Find(Action,SubClass: string): TCommandClass;
|
|
class procedure Init;
|
|
class procedure Done;
|
|
end;
|
|
|
|
implementation
|
|
{ TCommandCollection }
|
|
|
|
class procedure TCommandCollection.Register(ACommand: TCommandClass);
|
|
begin
|
|
fCollection.Add(ACommand);
|
|
end;
|
|
|
|
class function TCommandCollection.Find(Action, SubClass: string): TCommandClass;
|
|
var
|
|
i: integer;
|
|
begin
|
|
for i := 0 to fCollection.Count-1 do
|
|
if fCollection.Items[i].InheritsFrom(TCommand) and SameText(Action, TCommandClass(fCollection.Items[i]).CommandName) and SameText(SubClass, TCommandClass(fCollection.Items[i]).CommandSubClass) then
|
|
begin
|
|
result := TCommandClass(fCollection.Items[i]) ;
|
|
exit;
|
|
end;
|
|
for i := 0 to fCollection.Count-1 do
|
|
if fCollection.Items[i].InheritsFrom(TCommand) and SameText(Action, TCommandClass(fCollection.Items[i]).CommandName) and SameText('', TCommandClass(fCollection.Items[i]).CommandSubClass) then
|
|
begin
|
|
result := TCommandClass(fCollection.Items[i]) ;
|
|
exit;
|
|
end;
|
|
result := nil;
|
|
end;
|
|
|
|
class procedure TCommandCollection.Init;
|
|
begin
|
|
fCollection := TCommandCollection.Create;
|
|
end;
|
|
|
|
class procedure TCommandCollection.Done;
|
|
begin
|
|
fCollection.Free;
|
|
end;
|
|
initialization
|
|
TCommandCollection.Init;
|
|
finalization
|
|
TCommandCollection.Done;
|
|
|
|
end.
|
|
|