Search code examples
delphiruntimetclientdataset

Is it possible to create a use TClientDataSet in non visual unit or Inside an Class Object?


Is it possible to create and use a TClientDataSet inside an Object at runtime?

I like to make several changes in my Table and have those all Applied at the same time in cache like way, and TClientDataSet lets me do that. Know when I want to do this I have to build a TForm.

Is it Possible?

UPDATE

Can it be used, and How, without TDataSetProvider, and no TSQLQuery ? Because I tried it and it gave me an error no Provider!!


Solution

  • Components are just classes, and you can use them likewise:

    procedure TMyObject.DoSomeDBStuff;
    var
      localClientDataset: TClientDataset;
    begin
      localClientDataset := TClientDataset.Create( );
      try
    
      finally
        localClientDataset.Free;
      end;
    end;
    

    You can also make a clientdataset-property if you like:

    type
      TMyObject = class
      private
        FClientDB: TClientDataset;
      published
        property Dataset: TClientDataset read FClientDB;
      end;
    

    Some visual components may require a visual parent though, but for TClientDataset there should be no such requirement.