Delphi: using TClientDataset as an in-memory dataset

前端 未结 11 2184
无人及你
无人及你 2020-12-14 08:00

According to this page, it\'s possible to use TClientDataset as an in-memory dataset, completely independent of any actual databases or files. It describes how

相关标签:
11条回答
  • 2020-12-14 08:48

    If it helps further, here is a piece of code where I created a ClientDataset that is used as an in-memory table:

    procedure TfrmPRMain.ConfigureDataset;
    begin
      With cdsMain do begin
        FieldDefs.Add('bDelete', ftBoolean);
        FieldDefs.Add('sSource', ftString, 10);
        FieldDefs.Add('iSection', ftInteger);
        FieldDefs.Add('iOrder', ftInteger);
        FieldDefs.Add('sBranch', ftString, 10);
        FieldDefs.Add('sPulseCode', ftString, 10);
        FieldDefs.Add('sCode', ftString, 10);
        FieldDefs.Add('dtWorkDate', ftDate);
        FieldDefs.Add('iWorkWeek', ftInteger);
        FieldDefs.Add('sName', ftString, 50);
        CreateDataSet;
        LogChanges := False;
        Open;
      end;
    end;
    

    You can just substitute your own data information and go. Jack

    0 讨论(0)
  • 2020-12-14 08:48

    The code from this page doesn't work in ANY Delphi version. A call to CreateDataSet already puts the dataset into active state ("opened"). You should use .CreateDataSet OR .Open. Not both.

    Use .Open when you want to fetch data from a Provider (via ProviderName property) and .CreateDataSet when you want to populate the Dataset by yourself.

    BTW: For an in depth reference about ClientDataSets and its features take a look on excellent Cary Jensen articles on CodeGear Developer Network (read the oldest ones, first)

    0 讨论(0)
  • 2020-12-14 08:48

    If you'd like a dependency-free, high quality, and feature rich (not to mention free!) in-memory dataset, I highly recommend kbmMemTable. Does everything TClientDataset does and then some.

    0 讨论(0)
  • 2020-12-14 08:51

    for some reason this is not working for me. I perform CreateDataset in design time, but it still crashes application. That is still unknown for me. One warning. DO NOT DO THIS:

    XXXClientDataSet.Close;
    XXXClientDataSet.Open;
    

    because it will report error. Instead of Open, use

    xxxClientDataSet.CreateDataset;
    

    In my application I needed to reset data and load it again, and that again caused error message.

    0 讨论(0)
  • 2020-12-14 08:55

    Don't forget to include MIDAS.DLL in your installation or simply include MidasLib in uses clause. Otherwise using TClientDataSet will raise an error on client's machine. Maybe it's obvious, but I actually forgot this once.

    0 讨论(0)
提交回复
热议问题