[fpc-pascal] Problem accessing Class Method with abstraction

patspiper patspiper at yahoo.com
Sun Oct 17 10:03:50 CEST 2010


On 10/17/2010 05:54 AM, 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 :-(
>    
coItem is an object while coGeneric is a class

>        TPersistentClass(coItem):=coGeneric;<<  Compiles but get Runtime Error
>    
same as above
>        coItem.VerifyIDs(Module);<  CRASH @ RUNTIME
>      end;
>    end;
> end;
>
> How can I get each class's implement of VerifyIDs to get called as
> each one is different but yet single.
>    
Maybe using:
procedure TCoreObject.VerifyIDs(Var Module:TDBMSModule);
procedure TAdminCore.VerifyIDs(Var Module:TDBMSModule);





More information about the fpc-pascal mailing list