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

Joao Morais jcmoraisjr at gmail.com
Sun Nov 18 13:01:16 CET 2012


On Sun, Nov 18, 2012 at 3:13 AM, leledumbo <leledumbo_cool at yahoo.co.id> wrote:
>> Tell the user of the framework to do something like this for every
>> class of your model:
>>
>>   initialization
>>     TUser.RegisterClass;
>>     TProduct.RegisterClass;
>>     ...
>>
>> or
>>
>>   initialization
>>     RegisterClasses([TUser, TProduct, ...]);
>
> Seems like this is the most feasible way, there should be an internal data
> structure that maps registered classes with their respective table name.

Both RegisterClass procedures I pointed out are methods of the framework, eg:

// The framework

  type
    TBaseModelClass = class of TBaseModel;

   TBaseModel = class(TObject)
    public
      class procedure RegisterClass;
    end;

  procedure FWRegisterClass(AClasses: array of TBaseModelClass);

  ...

  class procedure TBaseModel.RegisterClass;
  begin
    // Initialize the class metadata. "ClassName" works.
    writeln('Registering ', ClassName);
  end;

  procedure FWRegisterClass(AClasses: array of TBaseModelClass);
  var
    I: Integer;
  begin
    for I := 0 to Pred(Length(AClasses)) do
      AClasses[I].RegisterClass;
  end;

// The application

  type
    TUser = class(TBaseModel);
    TContact = class(TBaseModel);

  implementation

  initialization
    FWRegisterClass([TUser, TContact]);


Joao Morais



More information about the fpc-pascal mailing list