[fpc-devel] Creating new classes at runtime
Mattias Gaertner
nc-gaertnma at netcologne.de
Sat Nov 13 03:35:23 CET 2004
On Fri, 12 Nov 2004 22:32:48 +0100 (CET)
Michael.VanCanneyt at Wisa.be wrote:
>
>
> On Fri, 12 Nov 2004, Mattias Gaertner wrote:
>
> >
> > I don't know, if this is the right list, but the topic is quite fpc specific and needs some compiler gurus:
> >
> > The Lazarus IDE needs to create new classes at runtime. For example when loading/creating a descendent of TDataModule named TMyDataModule,
> > it needs a unique TMyDataModule = class(TDataModule) complete with vmt, method table (empty), field table (empty), typeinfo
> > (no properties), and .. ?
> > At the moment lazarus only supports TDataModule and TForm, so I was able to just define the two and copy.
> > But for inheriting I need 'real' custom classes.
> >
> > Creating the empty method table, field table and new typeinfo seems to be easy. But I found some fields, which I don't know:
> > In objpash.inc there is
> > const
> > vmtInstanceSize = 0;
> > vmtParent = sizeof(ptrint)*2;
> >
> > The fields behind vmtParent are easy (at least I think so). But what about the 8 bytes (i386) behind vmtInstanceSize and in front of vmtParent?
> > They seem to be a negative number and a pointer? What are they are good for?
> >
> > And: Is this solution portable or will I get into trouble?
>
> What are you trying to do ?
Well, that's a long story ...
> As soon as you have the class, you know everything there is to know or that
> you need to know. You don't need to have more than the TMyClass class pointer.
Wow. That would be great.
> In the case of TMyDatamodule, you have the TMyDataModule class pointer, so
> You can create an instance and 'show' that on screen ?
Where do I get this TMyDataModule class pointer?
I also want TMyDataModule1, TMyOwnDataModule, TAnotherMyDataModule, ... . The classname should be different.
And I want a TMyGrandChildDataModule = class(TAnotherMyDataModule) = class(TMyDataModule) = class(TDataModule).
I only have a TDataModule class pointer. The rest should be created by the IDE just from class names.
But maybe I think too complicated. Fact is, I have class names and I need class pointers.
> For forms you must only assume it is a descendant of TCustomForm.
>
> The Delphi IDE also can only handle things that descend from TCustomForm and
> TDatamodule.
That's not sufficient. I want at least TComponent.
> When registering custom forms or datamodules in the IDE, you
> need to supply Delphi with the actual class pointer, and then it knows what
> to do...
> If you want I can show you code that registers custom forms in the Delphi
> IDE, I use it myself at work.
Yes, please enlighten me. :)
Mattias
More information about the fpc-devel
mailing list