[fpc-pascal] How to make class constructor body calls descendant's overriden method/property?

leledumbo leledumbo_cool at yahoo.co.id
Sat Nov 17 15:48:26 CET 2012


Cross posted from stackoverflow:
http://stackoverflow.com/questions/13431079/how-to-make-class-constructor-body-calls-descendants-overriden-method-property

I'm writing an ORM framework and got stuck in a way to automatically
determine table name from class name. In my base object for the ORM to work,
I have:

TghModel = class
...
  class var FTableName: String;
  class constructor Create;
...

whose implementation is:

class constructor TghModel.Create;
begin
  FTableName := ClassName;
  Delete(FTableName,1,1); // Delete 'T'
end;

My assumption was that ClassName method will return the real class name.
e.g. if I have:

TUsers = class(TghModel)

then FTableName will be initialized to TUsers instead of TghModel, which is
wrong. I want to avoid users to make class constructor for each classes
inheriting from TghModel, especially because the content would be totally
the same as in TghModel.Create. Is there any way to implement it?



--
View this message in context: http://free-pascal-general.1045716.n5.nabble.com/How-to-make-class-constructor-body-calls-descendant-s-overriden-method-property-tp5711994.html
Sent from the Free Pascal - General mailing list archive at Nabble.com.



More information about the fpc-pascal mailing list