Sign in Join

Live chat for Free Pascal, Lazarus, Delphi and every Pascal programmer.

Mailing lists / lazarus / 2009-01

How can I use TMemDataset

8 messages · 2 people · –

Reply by email Subscribe to this list Your subscription

Read-only archive. Use j and k to move between messages.

Gabor Boros

Hi,

I want to use an in memory dataset and found TMemDataset. But not working very well. If defined the fields in Object Incpector the whole thing unusable. Appended records with AppendRecord or with Append/Edit/Post not inserted into dataset. If define fields at run-time with FieldDefs.Add Append/Edit/Post working but AppendRecord not and Append/Edit/Post is just working on first try. Tried with FPC 2.2.2 and actual Lazarus SVN.

Anybody using TMemDateset?

Gabor

Reply by email

Joost van der Sluis
to Gabor Boros

Op maandag 05-01-2009 om 14:54 uur [tijdzone +0100], schreef Gabor Boros:

Show quoted text 7 lines
I want to use an in memory dataset and found TMemDataset. But not working very well. If defined the fields in Object Incpector the whole thing unusable. Appended records with AppendRecord or with Append/Edit/Post not inserted into dataset. If define fields at run-time with FieldDefs.Add Append/Edit/Post working but AppendRecord not and Append/Edit/Post is just working on first try. Tried with FPC 2.2.2 and actual Lazarus SVN.

For a working AppendRecord (for all TDatasets) you need a recent fpc svn version (2.2.3 or later)

I don't know how the Lazarus editor works, but for the rest, can you provide an example?

Anybody using TMemDateset?

If you use a recent fpc from svn you can alo use TBufDataset. It works the same like TMemDataset but it's used as basic for a few other datasets and is used more. (You can compare it to Delphi's TClientDataset)

Joost.

Reply by email

Joost van der Sluis
to Gabor Boros

Op maandag 05-01-2009 om 16:50 uur [tijdzone +0100], schreef Gabor Boros:

Provide an example for what? I don't understand you.

An example application which uses TMemDataset and apply/post/etc that does not work.

Joost.

Reply by email

Gabor Boros
to Joost van der Sluis

Under test case creation indentified the Append problem. I used Edit; after Append; and when removed the Edit; the record inserted properly to the DataSet. Below example works. But if put the MemDataset to the form set name to DSet add a field with the object inspector set name to NAME, set type to ftString and size to
20. Remove the first 2 lines after begin (.Create and .FieldDefs.Addd) the result (dset.txt) contains only the header. With dynamic creation the file contains the 2 records.

procedure DSet_Test;
var
   DSet:TMemDataset;
begin
   DSet:=TMemDataset.Create(Self);
   DSet.FieldDefs.Add('NAME',ftString,20);
   DSet.CreateTable;
   DSet.Open;
   DSet.Append;
   DSet.FieldByName('NAME').Value:='aaa';
   DSet.Post;
   DSet.Append;
   DSet.FieldByName('NAME').Value:='bbb';
   DSet.Post;
   DSet.SaveToFile('c:\dset.txt');
   DSet.Close;
end;

Gabor

Joost van der Sluis ?rta:

Show quoted text 14 lines
Op maandag 05-01-2009 om 16:50 uur [tijdzone +0100], schreef Gabor Boros: > Provide an example for what? I don't understand you. An example application which uses TMemDataset and apply/post/etc that does not work. Joost. _______________________________________________ Lazarus mailing list http://www.lazarus.freepascal.org/mailman/listinfo/lazarus

Reply by email

Joost van der Sluis
to Gabor Boros

Op maandag 05-01-2009 om 17:59 uur [tijdzone +0100], schreef Gabor Boros:

Under test case creation indentified the Append problem. I used Edit; after Append; and when removed the Edit; the record inserted properly to the DataSet.

Ok, that was a bug for all datasets. It's fixed in trunk now. The behaviour was consistent with the Delphi help: if Edit is called, first all changes are posted of when modified is false, cancelled.

So if you call Edit after Append, the Append is cancelled, and thereafter the prior record is edited.

But when the state of the dataset is dsEdit or dsInsert, Edit should do nothing. Also not posting/cancelling the record.

Thanks for the example.

Show quoted text 6 lines
Below example works. But if put the MemDataset to the form set name to DSet add a field with the object inspector set name to NAME, set type to ftString and size to 20. Remove the first 2 lines after begin (.Create and .FieldDefs.Addd) the result (dset.txt) contains only the header. With dynamic creation the file contains the 2 records.

My guess is that you also have to remove CreateTable? I'll look into it.

Joost.

Reply by email

Joost van der Sluis
to Gabor Boros

Op dinsdag 06-01-2009 om 07:43 uur [tijdzone +0100], schreef Gabor Boros:

The result is same with CreateTable and without CreateTable.

I've found the problem and fixed it in trunk. It was again a general issue, not only for TMemDataset. Thanks for the help.

Joost.

Reply by email