The Wiert Corner – irregular stream of stuff

Jeroen W. Pluimers on .NET, C#, Delphi, databases, and personal interests

  • My badges

  • Twitter Updates

  • My Flickr Stream

  • Pages

  • All categories

  • Enter your email address to subscribe to this blog and receive notifications of new posts by email.

    Join 4,184 other subscribers

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

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

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 :-)


PS: David Shwartz bumped into the same conceptual question; see [WayBackI’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+

4 Responses to “Delphi – TInterfacedDataModule revisted – use ‘inherited’ in your .dfm files when your datamodules look like forms in the designer”

  1. […] 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 […]

  2. Angel4585 said

    As posted here:
    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.

  3. Anonymous said

    […] […]

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.

%d bloggers like this: