1

I was wondering if there is a way to add tools to a data module's tool palette.

On a standard form under 'data access' tools I have a number of 'TXML' tools, however these aren't under 'data access' tools on a data module.

Can I add these or not?

Thanks,

Sharpie
  • 373
  • 2
  • 15
  • 34
  • 2
    Is the Classgroup of your Datamodue set? If the component you want use is Vcl you must set the ClassGroup to Vcl.Controls.Tcontrol – Fritzw Jul 21 '15 at 10:52
  • 1
    possible duplicate of [Delphi XE2 Data Module expects only database components?](http://stackoverflow.com/questions/14097246/delphi-xe2-data-module-expects-only-database-components) – Jerry Dodge Jul 21 '15 at 12:48

1 Answers1

-2

I don't know if you can add them to the tool palette, but you can use them if you create the objects yourself like in the example below.

unit Unit2;

interface

uses
  System.SysUtils, System.Classes,Xml.xmldom, Xml.XMLIntf,
  Xml.XMLDoc;

type
  TDataModule2 = class(TDataModule)
  private
    { Private declarations }
  public
    { Public declarations }
    procedure test;
  end;

var
  DataModule2: TDataModule2;

implementation

{%CLASSGROUP 'Vcl.Controls.TControl'}

{$R *.dfm}

{ TDataModule2 }

procedure TDataModule2.test;
var
  xml :TXMLDocument;
begin
try
   xml :=  TXMLDocument.Create();
finally 
   xml.Free;
end;
end;

end.

I've added to use the units for the XMLDocument, then i've created the object myself.

CiucaS
  • 2,010
  • 5
  • 36
  • 63
  • 1
    Sure this might work, but it doesn't solve OP's question. Also, why are you creating it under a procedure called `test` and never freeing it? Shouldn't it be created in `OnCreate` and free'd in `OnDestroy`? Sad, OP already accepted this. – Jerry Dodge Jul 21 '15 at 12:50
  • @JerryDodge you are right about forgeting to free it. But it's not necessary to create it onCreate, maybe he wants to use it localy only. I've said at the start of the post that I don't know if it's possible to add a component like this one to the tool palette of the DM and I gave him an alternative choise. – CiucaS Jul 21 '15 at 12:58
  • Well Stack Overflow isn't a guessing site. Things here are based on facts. In order to replicate the behavior of a design-time component, it must be created in `OnCreate` and free'd in `OnDestroy`. Also, your code not only won't compile (with no owner parameter in the XML constructor), but the creation should be before the `try` statement. – Jerry Dodge Jul 21 '15 at 13:40