On Sat, 16 Oct 2010, Andrew Brunner wrote:

I've got a class factory problem I'm trying to resolve and it appears
I'm at a point where it's probably better to ask for help.

 TCoreObjects=class;
 TCoreObject=Class (TPersistent)
 protected
   class procedure VerifyIDs(var Module:TDBMSModule); Virtual; abstract;
 end;
 TAdminCore=Class(TCoreObject)
 protected
   class procedure VerifiyIDs(var Module:TDBMSModule); override;
 end;

<SNIP>

procedure VerifyIDs(Var Module:TDBMSModule);
var
 iLcv:integer;
 ItemP:PCoreObjectItem; // Just record storing classname to load and
(each core object implment is loaded just not detailed here for
simplicity)
 coGeneric:TPersistentClass;
 coItem:TCoreObject;
begin
 for iLcv:=0 to High(CoreObjectItems) do begin
   ItemP:=CoreObjectItems[iLcv];
   coGeneric:=GetClass(ItemP^.ClassName);
   if (coGeneric<>nil) and coGeneric.InheritsFrom(TCoreObject) then begin
     coItem:=coGeneric as TCoreObject << COMPILER ERROR :-(

Of course it errors, you're trying to store a VMT in an object instance.

You chould declare

  TCoreObjectClass = Class (TCoreObject);

and
  coItem : TCoreObjectClass;

Then

  coItem:=TCoreObjectClass(coGeneric);
  coItem.VerifyIDs(Module);

Should work. Untested (not enough code provided) but I think the above should 
work.

Michael.
_______________________________________________
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
http://lists.freepascal.org/mailman/listinfo/fpc-pascal

Reply via email to