Read and Write in a TABLE lazarus / 16-Databases ---------------------------------------------------------------------- GUEST · 2005-06-09 15:08 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... ---------------------------------------------------------------------- Anonymous · 2006-06-13 13:32 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; TblName.First; FieldName := TblName.FieldByName('FieldName').AsInteger; Alright now you say you want to write to a table (AKA Add a record). TblName.Append; TblName.FieldByName('ID').AsInteger := 0; TblName.FieldByName('Name').AsString := 'John Doe'; ... TblName.Post; I hope this helps you out a little bit, if not you can get ahold of me through aim: boastingduck, or msn: rdg_32 ---------------------------------------------------------------------- Oscar · 2006-06-13 20:13 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       Mytables.Dbf_Landen.CreateTable; now you can fill the table like this : Mytables.Table1.Actieve:=True; Mytables.Table1.Insert; Mytables.Table1 .FieldByName('String1').AsString:='The text..'; Mytables.Table1.Post; Mytables.Table1.Active:=False; This works in my case..... Greetings Oscar