Quote
ullr...@math.okstate.edu wrote:
> > 3. Virtual methods only get linked in, if somewhere in the code there is
> > either an explicit construction call, or alternatively a call to
> > RegisterClasses....
> Here you lose me. Is this the way it's supposed to work according
> to the docs?
No... not explicitly.
Quote
> I don't see anything about this under "constructors"; this
> sounds like you're saying a virtual constructor can't be invoked using
> a class-reference type unless you call RegisterClass first(???: is
> this a guess or something you know? How do you know? I'm all confused.)
Okay. The deal works like this: The linking rules for methods in delphi
are:
a) Non virtual methods get linked in if there is a compiled call to the
method.
b) Virtual methods get linked in if the compiler can tell that an
instance of that class type is created.
The particular problem that often occurs is when you convert a string to
a class type (using GetClass or FindClass), and then try to use that
class. At compile time, the compiler can't work out which classes will
be created at run time, and thus the optimising linker has a habit of
removing them. In addition, one needs to include the relevant RTTI, so
that the call to GetClass or FindClass will succeed.
However, the case you have is slightly less pathological than this. In
theory, the compiler should be able to tell that the
"MyClass:=TMyGraphic" statement means that TMyGraphic is being created
polymorphically... however, I guessed at the time that it might not have
figured this, and thus not worked out what to call, thus the guess that
RegisterClass might do the trick.
Failing that, one might like to check that all the typing info required
is there, by declaring the class inside a {$M+} block.
I've certainly had this problem before, but in my case, I was using
GetClass to set a class reference variable, and then calling the
constructor for that (checking the base class had a virtual constructor,
the class reference type was "class of" the class that had the virtual
constructor, and that all descendant constructors were overrides). I
then had no problems at all. The only difference between your code and
mine is that you *aren't* using GetClass.
Are you sure that the class reference variable is being given the right
value at run time? Have you checked the result of
MyClassRef.Create.ClassName ?
Quote
> > Have you tried putting RegisterClass(TMyGraphic) in the initialisation
> > section???
> Have you tried it? I tried it just now, doesn't seem to make
> any difference.
Hmm.. yeah. In that case the problem proably isn't what I thought. It's
not very easy to tell without having a copy of the code to debug, not to
mention that fact that I really don't have the time to debug other
peoples code :-(
MH.
--
Martin Harvey.
Totally rewritten web pages at:
http://www.harvey27.demon.co.uk/mch24/
"ALGOL 60 was a language so far ahead of its time that it
was not only an improvement on its predecessors but also
on nearly all its successors". C.A.R. Hoare
--------------BEGIN GEEK CODE BLOCK--------------
Version: 3.12
GCS/CC d(+) s-:- a-- C+++$ UL@ P L@>++ E- W++
N+++ o-- K++ w+++$ O--- M-- V-- PS@ Y-- PGP-
t--- 5-- X-- R-- !tv b+ DI+ D+ G e++ h- r z++>---
---------------END GEEK CODE BLOCK---------------