Delphi – TInterfacedDataModule revisted – use ‘inherited’ in your .dfm files when your datamodules look like forms in the designer
Posted by jpluimers on 2009/08/20
I got a few comments about people implementing the TInterfacedDateModule from my post Delphi – Using FastMM4 part 2: TDataModule descendants exposing interfaces, or the introduction of a TInterfacedDataModule.
After applying the ideas, and reloading the datamodules in Delphi, some of you got datamodules that looked like forms in the designer. I’ve not seen this behaviour in the IDE myself, but it must be a bug somewhere.
I should have been clearer when writing about the solution for frames looking like forms in the designer from my post Delphi – Frames as visual Components – changing your inheritance: that solution also applies to datamodules. I hinted on that by writing This is caused by the fact that the IDE […] does not recognize as a designable class like TFrame or TDataModule, but only covered the TFrame case.
So time to cover the or TDataModule case as well. :-)
If your datamodule suddenly looks like the image on the right, and/or you get complaints about properties like ClientHeight, ClientWidth, OldCreateOrder, PixelsPerInch or TextHeight, then need to change your dfm file.
A dfm file for a datamodule that indirectly descends from TDataModule should not have the object keyword as the first like this listing:
object MyDataModule: TMyDataModule Left = 0 Top = 0 ClientHeight = 213 ClientWidth = 183 Color = clBtnFace Font.Charset = DEFAULT_CHARSET Font.Color = clWindowText Font.Height = -11 Font.Name = 'Tahoma' Font.Style = [] OldCreateOrder = True PixelsPerInch = 96 TextHeight = 13 object DataSource1: TDataSource Left = 64 Top = 38 end end
In stead, such a dfm file should start with the inherited keyword as the first like this listing:
inherited MyDataModule: TMyDataModule OldCreateOrder = True Width = 190 object DataSource1: TDataSource Left = 64 Top = 38 end end
If you do so, then it will look like the picture on the right side again.
Hope that solves a few issues for a couple of you :-)
–jeroen
PS: David Shwartz bumped into the same conceptual question; see [WayBack] I’d like some insight about an architectural question that I’m having trouble with. Let’s say I have some Delphi DataModules that are used to contain… – David Schwartz – Google+
Delphi Eigenen Fenstertyp erstellen/registrieren? - Delphi-PRAXiS said
[…] Heute, 19:56 Vielleicht object statt inherited im dfm? Schau mal was Jeroen dazu schreibt. Ibi fas ubi proxima merces sudo /Developer/Library/uninstall-devtools […]
Angel4585 said
As posted here: http://www.delphipraxis.net/177739-vererbung-zwischen-tdatamodules-wird-staendig-geloest.html#post1238304
It seems to be a bug in the IDE. When I click the compiler-button or CTRL+F9 the inheritance between two DataModules is released.
If you don’t change the size of the child only Height and Width is added to the sourcecode.
But if you change the size ClientWidth and ClientHeight is added.
If you change from object to inherited in Text-Mode manually you also need to switch to Designer-Mode to get and ignore all the Error-Messages.
If you don’t switch back, you get these messages on Runtime.
jpluimers said
Thanks for the update. I’ll try and see if I can reproduce this.
Anonymous said
[…] […]