On Sun, Oct 17, 2010 at 3:33 AM, Michael Van Canneyt <mich...@freepascal.org> wrote:
<SNIP> // Revised code CCoreObject=Class(TCoreObject); 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; procedure TCoreObjects.Load; var iLcv:integer; coGeneric:TPersistentClass; ItemP:PCoreObjectItem; coItem:TCoreObject; id:IStringsAdapter; begin if FInfo.Loaded then exit; for iLcv:=0 to High(CoreObjectItems) do begin ItemP:=CoreObjectItems[iLcv]; coGeneric:=GetClass(ItemP^.ClassName); if (coGeneric<>nil) then Add(iLcv,coGeneric); end; FInfo.Loaded:=True; end; procedure TCoreObjects.Add(iCoreItemIndex:integer; Item:TPersistentClass); var iIndex:integer; coItem:TCoreObject; begin if Item.InheritsFrom(TCoreObject) then begin coItem:=Item.Create as TCoreObject; iIndex:=Add(coItem); Copy(CoreObjectItems[iCoreItemIndex]^,coItem.Header); coItem.OwnerP:=...@finfo; coItem.Initialize; end; end; <OMITTED> procedure VerifyIDs(Var Module:TDBMSModule); var iLcv:integer; ItemP:PCoreObjectItem; coGeneric:TPersistentClass; coItem:CCoreObject; 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 CCoreObject; // did not compile coItem:=TCoreObjectClass(coGeneric); // Compiles coItem.VerifyIDs(Module); // SIGEV end; end; end; It's crashing with SIGEV error. I think b/c at that point the class reference becomes a TCoreObjectClass with pointer to abstracted method not the TAdminCore.VerifyIDs method. Take TCoreObjects.Add(iCoreItemIndex:integer; Item:TPersistentClass); for a point of discussion... It has no problems loading and creating instances of descendant core objects as they are presently running and referenced throughout the project. So while this method accepts the as TCoreObject the as keyword does not work for class references. How can I leave these class references as generic but yet still access the implmented method of the descendant class? _______________________________________________ fpc-pascal maillist - fpc-pascal@lists.freepascal.org http://lists.freepascal.org/mailman/listinfo/fpc-pascal