Sign in Join

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

Mailing lists / lazarus / 2008-04

Is anyone working with the simple datasets?

9 messages · 4 people · –

Reply by email Subscribe to this list Your subscription

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

Felipe Monteiro de Carvalho

Hello,

I just tryed to investigate a TDBMemo bug, but I found myself completely unable to create any database app, using the simple datasets so I am curious to know if anyone is using the simple datasets with FPC 2.2.0 (TMemDataset, TFixedFormatDataset, TDBf).

I tested both TMemDataset, TFixedFormatDataset and TDBf and none worked. Both with a table with just 1 field, of string or memo type. TMemDataset ignores what I write to it, and when I change record and come back it gets erased, TDBf will say the file I just created with CreateTable is invalid, and I couldn't find any documentation about how to create the file for the fixed format dataset...

Everything in Linux.

thanks,

Felipe Monteiro de Carvalho

Reply by email

Graeme Geldenhuys
to Felipe Monteiro de Carvalho
Felipe Monteiro de Carvalho wrote
datasets so I am curious to know if anyone is using the simple datasets with FPC 2.2.0 (TMemDataset, TFixedFormatDataset, TDBf).

I also struggled in the beginning with DB components in Lazarus and found some strange properties which could clash (message thread of about two or three months ago). fpGUI has a TDBF example in the examples/gui/dbtest/ directory, if that might help.

http://fpgui.svn.sourceforge.net/viewvc/fpgui/trunk/examples/gui/dbtest/

------------[ snippet ]-------------------
constructor TMainForm.Create(AOwner: TComponent);
var
   x: Integer;
   s: string;
begin
   inherited Create(AOwner);
   DataSet             := TDBF.Create(Self);
   DataSet.TableName   := 'test.dbf';
   DataSource          := TDataSource.Create(Self);
   DataSource.DataSet  := DataSet;
   dblblName.DataSource    := DataSource;
   dblblName.DataField     := 'Name';
   dblblEMail.DataSource   := DataSource;
   dblblEMail.DataField    := 'Address';
   DataSet.Open;
   while not DataSet.EOF do
   begin
     SetLength(s, 0);
     for x := 0 to DataSet.FieldCount - 2 do
       s := s + DataSet.Fields[x].AsString + ', ';
     s := s + DataSet.Fields[DataSet.FieldCount - 1].AsString;
     lstName1.Items.Add(s);
     DataSet.Next;
   end;
   DataSet.First;
end;
------------[ end ]--------------------

Regards,
- Graeme -

_______________________________________________________ fpGUI - a cross-platform GUI toolkit using Free Pascal http://opensoft.homeip.net/fpgui/

Reply by email

Graeme Geldenhuys
to Felipe Monteiro de Carvalho
Felipe Monteiro de Carvalho wrote
Thanks, but how did you create the dbf file for the example?

Pretty easy... :-)

uses
   dbf, dbf_fields;
constructor TMainForm.Create(AOwner: TComponent);
var
   fields: TDbfFieldDefs;
begin
   inherited Create(AOwner);
   DataSet             := TDBF.Create(Self);
   DataSet.TableName   := 'temp.dbf';
   fields := TDbfFieldDefs.Create(self);
   fields.Add('Name', ftString, 50);
   fields.Add('Address', ftString, 150);
   DataSet.CreateTableEx(fields);  // <== Now we have a empty database
   DataSet.Open;
   Dataset.Insert;  // <== start inserting data
   Dataset.FieldByName('Name').AsString := 'Graeme';
   Dataset.FieldByName('Address').AsString := ';
   DataSet.Post;
   ....
end;

Regards,
- Graeme -

_______________________________________________________ fpGUI - a cross-platform GUI toolkit using Free Pascal http://opensoft.homeip.net/fpgui/

Reply by email

Graeme Geldenhuys
to Felipe Monteiro de Carvalho: Thanks, but how did you create the dbf file for the example? Felipe Monteiro de Carvalho
Felipe Monteiro de Carvalho wrote
Thanks, but how did you create the dbf file for the example?

I extended the 'dbtest' example to show the code used to create the dbf file (for future reference). But it's the same code as my previous post.

Regards,
- Graeme -

_______________________________________________________ fpGUI - a cross-platform GUI toolkit using Free Pascal http://opensoft.homeip.net/fpgui/

Reply by email

Felipe Monteiro de Carvalho
to Graeme Geldenhuys: Pretty easy... :-) uses dbf, dbf_fields; constructor TMainForm.Create(AOwner: TComponent);
Graeme Geldenhuys wrote 8 lines
constructor TMainForm.Create(AOwner: TComponent); var fields: TDbfFieldDefs; begin inherited Create(AOwner); DataSet := TDBF.Create(Self); DataSet.TableName := 'temp.dbf';

..........

Thanks, this worked perfectly =) Maybe the problem with TDBf is that I was passing zero to the size of the string field. I had just thougth that I don't care about the size and giving zero would make it a field that can accept any size ...

Felipe Monteiro de Carvalho

Reply by email

Graeme Geldenhuys
to Felipe Monteiro de Carvalho
Felipe Monteiro de Carvalho wrote 5 lines
Thanks, this worked perfectly =) Maybe the problem with TDBf is that I was passing zero to the size of the string field. I had just thougth that I don't care about the size and giving zero would make it a field that can accept any size ...

You're creating a database table with fields. If the field is a string type it needs a size limit (that's valid for any database design). Otherwise make it a BLOB or MEMO type, where no size needs to be specified.

Regards,
- Graeme -

_______________________________________________________ fpGUI - a cross-platform GUI toolkit using Free Pascal http://opensoft.homeip.net/fpgui/

Reply by email

Joost van der Sluis
to Felipe Monteiro de Carvalho: On Mon, Apr 14, 2008 at 10:05 AM, Graeme Geldenhuys .......... Thanks, this worked…

Op maandag 14-04-2008 om 20:35 uur [tijdzone -0300], schreef Felipe Monteiro de Carvalho:

Show quoted text 16 lines
On Mon, Apr 14, 2008 at 10:05 AM, Graeme Geldenhuys wrote: > constructor TMainForm.Create(AOwner: TComponent); > var > fields: TDbfFieldDefs; > > begin > inherited Create(AOwner); > DataSet := TDBF.Create(Self); > DataSet.TableName := 'temp.dbf'; .......... Thanks, this worked perfectly =) Maybe the problem with TDBf is that I was passing zero to the size of the string field. I had just thougth that I don't care about the size and giving zero would make it a field that can accept any size ...

You shoudn't think, but look it up. ;) Normally databases do not have 'sizeless' fields. That would be way too inefficient. There are BLOB's (clob's?) for that purpose.

Note that if you define a string field with a size of 5000, for each record 5000 bytes of memory will be allocated. Two such fields, 100 records and your dataset need at least 1 MB of memory....

Joost.

Reply by email