Recent

Author Topic: In Memory dataset woes  (Read 25765 times)

TheBlackSheep

  • Jr. Member
  • **
  • Posts: 93
Re: In Memory dataset woes
« Reply #15 on: June 07, 2011, 09:59:56 pm »
It's true - in the traditional sense the TRxMemoryData doesn't support filtering as in;

RxMemoryData.Filter := 'fieldname1 = "'+SrchCriteria+'"';
RxMemoryData.Filtered := True;

this doesn't work.

However, you can do the follwing; double-click on the OnFilterRecord event and set this instead;

Accept :=  RxMemoryData.FieldByName('fieldname1').asString = SrchCriteria;

set the RxMemoryData.Filter to empty (i.e. '' - although this maybe irrelevant as I think it just ignores it) and the RxMemoryData.Filtered to true to set this filter on.  Might be slightly more complicated to generate a dynamic filter but as you can use normal Pascal functions here you can get more versatility than the standard filter.

See here for an example using Pos() (note: the parameters for Pos are the wrong way around in the example shown);

http://www.festra.com/wwwboard/messages/13525.html

Of course, it does support Locate, Bookmarks etc.

I was slightly disappointed when the recordcount didn't appear to be affected by the filtering (as I think is the case in most "proper" datasets) but I've tested the JVCL one and it doesn't appear to change the recordcount when it's filtered either (looking at the source for both they're just a return of the number of entries in a TList instance so this is hardly surprising).  If you need this then you'd have to manually count them.

In summary, I think it works well and does a lot of simple small-scale data-structure management problems - if you need more functionalty then there's possibly the free version of Kim Madsen's TkbmMemTable [he's confirmed it does work with Lazarus - it's overkill for my purpose in this instance] or use a SQLite in-memory table (I use the Zeos connection component just set the propotol to sqlite-3 and the database to ":memory:" but you will need to create the tables/indexes on the fly - however, this isn't too difficult).

Chris

tatamata

  • Hero Member
  • *****
  • Posts: 787
    • ZMSQL - SQL enhanced in-memory database
Re: In Memory dataset woes
« Reply #16 on: June 26, 2011, 08:48:46 am »
It seems that Refresh method deletes all records from a bufdataset.
I have posted a bugreport here:
http://bugs.freepascal.org/view.php?id=19631

liewald

  • Full Member
  • ***
  • Posts: 142
Re: In Memory dataset woes
« Reply #17 on: July 11, 2011, 03:31:09 pm »
Still having problems!
when I create dataset can populate etc but if I try to add an index no data appears in the dataset and no error is generated

Here is some demo code

unit Unit1;

{$mode objfpc}{$H+}

interface

uses
  Classes, SysUtils, db, memds, FileUtil, Forms, Controls, Graphics,
  Dialogs, StdCtrls, DBGrids, bufdataset;

type

  { TForm1 }

  TForm1 = class(TForm)
    BufDataset1: TBufDataset;
    Datasource1: TDatasource;
    DBGrid1: TDBGrid;
    MemDataset1: TMemDataset;
    Quit: TButton;
    PopulateDataset: TButton;
    Memo1: TMemo;
    ReadDataset: TButton;
    ConnectDataset: TButton;
    procedure ConnectDatasetClick(Sender: TObject);
    procedure FormCreate(Sender: TObject);
    procedure PopulateDatasetClick(Sender: TObject);
    procedure QuitClick(Sender: TObject);
    procedure ReadDatasetClick(Sender: TObject);
  private
    { private declarations }
  public
    { public declarations }
    thedata: Tbufdataset;
    procedure Create_A_Dataset;
  end;

var
  Form1: TForm1;

implementation

{$R *.lfm}

{ TForm1 }

procedure TForm1.Create_A_Dataset;

begin
thedata := Tbufdataset.Create(self);
with thedata.FieldDefs do
 begin
   add('Field1',ftstring,10,true);
   add('Field2',ftstring,10,true);
   add('Field3',ftstring,10,true);
   add('Field4',ftstring,10,true);
   add('Field5',ftstring,10,true);
 end;
 thedata.MaxIndexesCount:= 100;
 thedata.createdataset;
 thedata.open;
 thedata.AddIndex('Field1idx','Field1',[ixPrimary]);   // Rem this line and next for code to work
 thedata.IndexName:= 'Field1idx';                                //Rem this line for code to work


end;

procedure TForm1.FormCreate(Sender: TObject);
begin
 Create_A_Dataset;
end;

procedure TForm1.ConnectDatasetClick(Sender: TObject);

begin
Datasource1.DataSet := thedata;
end;

procedure TForm1.PopulateDatasetClick(Sender: TObject);

var I,J,thevalue : integer ;
    thefieldname: string;
begin
for i := 1 to 100 do
begin
thedata.Append;
for j := 1 to 5 do
begin
  thefieldname := 'Field' + inttostr(j);
  thevalue := i + j;
  thedata.FieldByName(thefieldname).asstring := inttostr(thevalue);
end;
thedata.post;
end;
end;

procedure TForm1.QuitClick(Sender: TObject);
begin
  application.Terminate;
end;

procedure TForm1.ReadDatasetClick(Sender: TObject);

  var tempstr: string;
    i : integer;
begin

 memo1.Clear;
 thedata.First;
 while not thedata.EOF do
 begin
   tempstr  := '';
   for i := 0 to 4 do
   tempstr := tempstr + thedata.Fields.value + ' ';
   memo1.Append(tempstr);
   thedata.next;
 end;
end;

end.       

mytimeman

  • New Member
  • *
  • Posts: 10
Re: In Memory dataset woes
« Reply #18 on: August 05, 2011, 09:37:21 am »
Hi, I've posted a possible update to the existing rx dataset (TRxMemoryData) to give it persistence based on the TBufDataset structure.

This may be of interest.

http://lazarus.freepascal.org/index.php/topic,14118.0.html


 

TinyPortal © 2005-2018