1

I am trying to define generics datamodule, something like this:

TDM<T> = class(TDataModule)
public
  function GetValue:T;virtual;abstract;
end;

But when I do this, Delphi misunderstood the datamodule and thinks its form (adds form properties like Client Width, Font, ... to .dfm file). I want this datamodule only for inheritance, so I tried to make it as simple class without .dfm file and then make real datamodule (with .dfm file) which inherits from it. Example:

TDataModule2 = class(TDM<Integer>)
public
  function GetType:Integer;override;
end;

Everything looks great, but only to moment, when I close and open project. On project opening, Delphi again interprets TDataModule2 as form for some reason (which causes exceptions on run).

I'm using Delphi XE. Is there any way to make this possible?

Dave
  • 83
  • 1
  • 4
  • I don't think it is possible. Form Designer is EXTREMELY dumb thing. It even does not support type overriding for events... TDM is input a type but only a template. Type would be like TDM or TDM You'd frankly better make custom class and embed datamodule as its internal object – Arioch 'The Aug 08 '12 at 11:54
  • check your .dfm file in text mode, most likely your datamodule is defined as inherited, change to object and you should be fine... – whosrdaddy Aug 08 '12 at 12:05
  • How did you create the unit containing TDM? "New Unit" or "New Datamodule"? – Uwe Raabe Aug 08 '12 at 13:26
  • @UweRaabe With "New Unit". I also tried "New Datamodule", but that way I couldn't make even TDM working, it was almost instantly interpreted as Form. – Dave Aug 08 '12 at 16:12
  • @whosrdaddy I tried both object and inherited, no good results. – Dave Aug 08 '12 at 16:13
  • @Arioch'The I think you are right, really dumb. I already found some workaround for my case, but it would be nice, if this would be improved in some newer version of Delphi. – Dave Aug 08 '12 at 16:16
  • frankly, i cannot see much to improve here. About enhancing generics, I'd like to see co-variance/contra-variance implemented, so i could create collection of collections. But about this... With form designer you create some class. Tsomething is not class. Ergo - you cannot design it. Well, Form Designer should just refuse to do it, rather than show mostly senseless "that is form" behaviour. But it would not design it anyway. – Arioch 'The Aug 09 '12 at 12:12
  • @Arioch'The Yes, a don't want it to design TSomething. Improvement I would appreciate is to design correctly descendant of TSomething, like TChild=class>. I think this can be done. – Dave Aug 09 '12 at 12:33

0 Answers0