[fpc-pascal]How to copy classes and methods?
peter at freepascal.org
Sun Dec 31 17:27:47 CET 2000
At 16:15 31-12-00, you wrote:
> > > I want to create a new class and add/remove methods at runtime.
> > > I copy the vmt of an existing class and alter the method table. But I
> > > to know how big is the vmt of a class?
> > > And I have to create published DoNothing procedures. Can I copy the
> > > code of an existing procedure? How big is the code of a procedure?
> > I also am not sure whether you should try to do so. Copying VMT's is low
> > level object pascal. What is it you are trying to accomplish? Why do you
> > want to create a new class and add/remove methods at runtime? Maybe
> > are better ways of doing so.
> > Vincent Snijders
>I'm writing code for a wysiwyg component editor. (lazarus. Which is open
>source, so it should help any other IDE project too).
>I'm using TReader, TWriter and the whole RTTI to edit components of unknown
>classes. All procedures in the FCL depend on real classes, and not classes
>with some fake methods. And because I want to use the FCL, I need a real
>class. Thus I create one at runtime and add/remove the methods.
>Ok, it is low-lvl object pascal, but it is much easier than rewriting the
>How big is the VMT of a class?
For all details how a VMT is build see compiler/hcgdata.pas this is the
file of the compiler that generates the VMT.
>Can I copy the code of an existing procedure? What is the size of the code
>of a procedure?
You can't copy a procedure as it can contain relative memory addresses that
aren't valid anymore if run from an other location in memory.
More information about the fpc-pascal