Board index » delphi » Can't assign a TFont to a TFont problem

Can't assign a TFont to a TFont problem

With Delphi 2, I built an application that creates forms but does not
display them. Instead, it switches parentage of the main panel in each
form to a main application window. This provides SDI look-and-feel
efficiency with the benefits of MDI.

Anyhow, when I built it as a single EXE, everything works well. Then I
decided to split off a group of forms into a DLL. When a form object is
delivered from the DLL, the application fails with the message "Can't
assign a TFont to a TFont". Does anyone have any idea why this might
happen from a DLL?

I have several levels of inheritance from TForm. I doubt if this causes
the problem.

I looks at the VCL source code in "Classes.pas". The problem is spawned
from the class TPersistant. However, I don't understand how this is
happening. Again, the DLL seems to be the problem. Any help would be
appreciated.

Stuart Adamic
Essex Data Services Ltd.

 

Re:Can't assign a TFont to a TFont problem


_snip_

Quote
> Anyhow, when I built it as a single EXE, everything works well. Then I
> decided to split off a group of forms into a DLL. When a form object is
> delivered from the DLL, the application fails with the message "Can't
> assign a TFont to a TFont". Does anyone have any idea why this might
> happen from a DLL?

Stuart,

its because the DLL has a separate instance of the VCL code and thus there
are two TFont classes around, one in the EXE, one in the DLL. Since your
panels have the ParentFont property set to true somewhere a
thepanel.font.assign( form.font ) statement is executed. The first thing
the Assign funtion does it a If passedObject Is TFont Then test. The Is
test in this case basically compares the objects classtype (a property that
yields a pointer to the TFont class structure in the DLL in this case) to
the address of the TFont class structure in the EXE. Of course these are
not identical and thus the test fails.

Even if you set ParenFont to false to avoid this particular problems you
are likely to run into more problems rooted in the same cause: mixing two
instances of the VCl source.

Peter Below (TeamB)  100113.1...@compuserve.com)

Re:Can't assign a TFont to a TFont problem


Quote
In article <354741FB.76460...@v-wave.com>, Stuart Adamic wrote:
> Does anyone have any idea why this might
> happen from a DLL?

I know why, but cannot offer a workaround.

TFont.Assign only knows how to assign from another TFont, so it checks
that the incoming argument is a TFont.  In this case, the DLL has one
declaration of the TFont class and the main program has its own
declaration.  So you have two TFont classes, identical twins if you
wish, but not the same object.  So the test fails and generates the
error.

In D3, you could compile with packages, and the main program and DLL
would share a single definition of TFont, and you would not have this
problem.

Re:Can't assign a TFont to a TFont problem


Thanks for the quick response, Peter. I have been debating switching to
D3. The concept of packages sounds like the thing I need. Thanks again.

Stuart Adamic
Essex Data Services Ltd.

Other Threads