Create instance from Classtype

(Friedrich Westermann) #1

I have these declarations:

TCwBaseTableClass = public class of TCwBaseTable;

TCwBaseTable = public class( ICwBaseTable) …

and a Dictionary<String, TCwBaseTableClass>;

method getICwTable(const aClassname: String; aBase: IDBcwDatabase): ICwBaseTable;
  if gTableClasses.ContainsKey(aClassname) then
  // if i Create a local var it works
    var lClass : TCwBaseTableClass;
    lClass := gTableClasses[aClassname];
   exit new lClass(aBase) as ICwBaseTable;
   // But
   // Why is these not working? 
   // I get error E130: Type expected
   // exit new gTableClasses[aClassname](aBase) as ICwBaseTable;
  else exit nil;

(Carlo Kok) #2

That’s because it’s an ambigious syntax; ie new Integer[15] vs new Something(). If you add parenthesis it probably works:

exit new (gTableClasses[aClassname])(aBase) as ICwBaseTable;

(Friedrich Westermann) #3

works! Thanks a lot!