It is possible to create (register) a new class at runtime using delphi.
I have a class called TMyForm, it is possible to create a new form derived from TMyForm, but with a new class type.
I need something like this
var Myform : TMyForm; MyFormClassBase : TFormClass; begin MyFormClassBase := TFormClass(RegisterMyNewClass('TMyNewClass'));//obviously RegisterMyNewClass does not exist Myform := MyFormClassBase.Create(Application); Myform.Show; end;
I am using delphi 7
UPDATE 1
I'm not looking to create a new instance of the same base class, I need to create a new type of class at runtime derived from another class.
UPDATE 2
Thanks so much for your interest. but the goal is a little complicated to explain (because my bad english). I have a form that allows you to edit several master data tables, all these tables have the same field code (integer primary key) and description (varchar field), they serve to determine currencies, countries, projects, groups, etc.
since the logic is the same for all of these tables, so this form is needed, passing as the parameters the header of the table name to manage these tables. something like that
FormCurrency:= TMyForm.Create( 'Define currencys', 'CURRENCYTABLE') if ValidateAccess(FormCurrency) then FormCurrency.Show else FormCurrency.Close; FormGroups:= TMyForm.Create( 'Define Groups', 'GROUPSTABLE') if ValidateAccess(FormGroups) then FormGroups.Show else FormGroups.Close;
On the other hand, I have a validation method (called ValidateAccess) that checks user access to forms using the form class. because of this, if you use the same form, this is limited access to all parameters, such as "define groups", "define currencys", "define countrys" (which I do not want this to happen), because I need pass to ValidateAccess method is another class.
I cannot rewrite the ValidateAccess method because there are many different forms already registered in the system.
I do not want to create a new type of form and a new block again and again, just changing the title and table to use.
Thanks at Advance.