esby
7th January 2005, 01:33
the structure first ...
type
class TClip = class
private
<snip> // some datas
public
constructor create;
class function Screate:TClip; virtual; abstract;
class function ClipIdent:string; virtual; abstract;
<snip>
end;
class TClipDerived = class (TClip)
public
constructor create;
class function Screate:TClip; override;
class function ClipIdent:string; override;
end;
class TClipDerived2 = class (TClip)
public
constructor create;
class function Screate:TClip; override;
class function ClipIdent:string; override;
end;
var
filterTypeList:TClassList;
end;
Implementation
{TClip}
constructor TClip.create;
begin
<snip>
end;
{TClipDerived}
creator TClipDerived.create;
begin
inherited create;
<snip>
end;
Class function TClipDerived.Screate:TClip;
begin
result := create;
end;
class function TClipDerived.ClipIdent: string;
begin
result :='TClipDerived';
end;
{TClipDerived2}
creator TClipDerived2.create;
begin
inherited create;
<snip>
end;
Class function TClipDerived2.Screate:TClip;
begin
result := create;
end;
class function TClipDerived2.ClipIdent: string;
begin
result :='TClipDerived2';
end;
initialization
filterTypeList := TClassList.Create;
filterTypeList.Add(TClipDerived);
filterTypeList.Add(TClipDerived2);
Now the problem...
filterTypeList inventories the different filters available...
Now I want to instanciate any clip i could need according to its clipIdent string.
for example, if I need a TClipDerived2 instance
I call
clip := InvokeClip('TClipDerived2');
with
function InvokeClip(str:string):TClip;
var i:integer;
clip:TClip;
begin
result := nil;
i:=0;
while (result=nil) and (i< filterTypeList.Count)
do begin
clip := TClip(filterTypeList.Items[i].NewInstance);
if AnsiSameText(str,clip.ClipIdent)
then result := clip.Screate;
clip.free;
end;
end;
But to achieve that, I am finding that the InvokeClip is a bit too hackish for me... as I create a dummy instance of any class stored in the class list, which I check versus classIdent...
Any better solution?
thanks in advance.
esby
type
class TClip = class
private
<snip> // some datas
public
constructor create;
class function Screate:TClip; virtual; abstract;
class function ClipIdent:string; virtual; abstract;
<snip>
end;
class TClipDerived = class (TClip)
public
constructor create;
class function Screate:TClip; override;
class function ClipIdent:string; override;
end;
class TClipDerived2 = class (TClip)
public
constructor create;
class function Screate:TClip; override;
class function ClipIdent:string; override;
end;
var
filterTypeList:TClassList;
end;
Implementation
{TClip}
constructor TClip.create;
begin
<snip>
end;
{TClipDerived}
creator TClipDerived.create;
begin
inherited create;
<snip>
end;
Class function TClipDerived.Screate:TClip;
begin
result := create;
end;
class function TClipDerived.ClipIdent: string;
begin
result :='TClipDerived';
end;
{TClipDerived2}
creator TClipDerived2.create;
begin
inherited create;
<snip>
end;
Class function TClipDerived2.Screate:TClip;
begin
result := create;
end;
class function TClipDerived2.ClipIdent: string;
begin
result :='TClipDerived2';
end;
initialization
filterTypeList := TClassList.Create;
filterTypeList.Add(TClipDerived);
filterTypeList.Add(TClipDerived2);
Now the problem...
filterTypeList inventories the different filters available...
Now I want to instanciate any clip i could need according to its clipIdent string.
for example, if I need a TClipDerived2 instance
I call
clip := InvokeClip('TClipDerived2');
with
function InvokeClip(str:string):TClip;
var i:integer;
clip:TClip;
begin
result := nil;
i:=0;
while (result=nil) and (i< filterTypeList.Count)
do begin
clip := TClip(filterTypeList.Items[i].NewInstance);
if AnsiSameText(str,clip.ClipIdent)
then result := clip.Screate;
clip.free;
end;
end;
But to achieve that, I am finding that the InvokeClip is a bit too hackish for me... as I create a dummy instance of any class stored in the class list, which I check versus classIdent...
Any better solution?
thanks in advance.
esby