Author Topic: Read and Write in a TABLE  (Read 4120 times)


  • Guest
Read and Write in a TABLE
« on: June 09, 2005, 05:08:15 pm »
Hi, I'm New in Lazarus but I'm a Delphi User, I'm think that Lazarus is excellent, It will become a Standar in Object Pascal Programing, I'm sure.

I have a question about tdbf component, someone can tell me how can I read or write fields in a table using this package? I'm trying to do it but I get a error message, maybe something wrong in my code, but if someone post a piece of code when Read or Write a new field in a DBF table I'll be very thankful

Sorry about my english...


  • Guest
RE: Read and Write in a TABLE
« Reply #1 on: June 13, 2006, 03:32:23 pm »
In order to read certain fields in a table you would do the following:

FieldName := TblName.FieldByName('FieldName').AsInteger
// [ Note: AsString, AsFloat, AsDateTime, and many more also exist ]

However that doesn't always work if you're trying to figure out a specific record's data, in that case you would have to filter for that record using your primary key.

TblName.Filter := 'ID=0';
TblName.Filtered := True;
FieldName := TblName.FieldByName('FieldName').AsInteger;

Alright now you say you want to write to a table (AKA Add a record).

TblName.FieldByName('ID').AsInteger := 0;
TblName.FieldByName('Name').AsString := 'John Doe';

I hope this helps you out a little bit, if not you can get ahold of me through aim: boastingduck, or msn: rdg_32


  • New member
  • *
  • Posts: 6
Read and Write in a TABLE
« Reply #2 on: June 13, 2006, 10:13:06 pm »
I'm also using the TDBF Table system. I always do the folowing :

Create a Datamodule, let's say I call it "Mytables"

al the tables you use in your program are declares in the Datamodule. you make a Table withe a Datasource and call it , lets say Table1 with en few string fields.

Now you can do the following :

Create the table if it not exists :

  Mytables.Table1 .Active:=False;
  Mytables.Table1 .FilePath:='C:\data';
  Mytables.Table1 .FilePathFull:='C:\data';
  Mytables.Table1 .TableName:='Table1.dbf';
  if FileExists('C:\data\Landen.Dbf') = False then    

now you can fill the table like this :
Mytables.Table1 .FieldByName('String1').AsString:='The text..';

This works in my case.....

Greetings Oscar
Take a homebrew !!
Creating software for it :