[Solved] DBF Locate then Edit lazarus / 16-Databases ---------------------------------------------------------------------- jonek · 2010-01-12 16:28 Hi. I fear I am about to betray my newbie status... I have a DBF table. I use it to manually populate a TListBox. I would like the user to click on a name in the list and click an edit button, which then throws up an edit box to allow them to change the name, then repost it to the database. Here's the code at the moment. Code: [Select]begin   if UsersList.ItemIndex=-1 then Exit;   if not UsersTable.Locate('NAME',UsersList.Items[UsersList.ItemIndex],[]) then   begin     MessageDlg('Error 103',mtError,[mbOK],0);     Exit;   end;   EditName:=UsersTableName.Text;   repeat     if not InputQuery('Edit user', 'Re-enter the user''s name',EditName) then Exit;   until EditName<>'';   UsersTable.Edit;   UsersTableName.Text:=EditName;   UsersTable.Post;   BuildUsersList; end; I don't get error 103. The name in the InputQuery is correct. BuildUsersList is my own routine to repopulate the list. But when finished editing and click OK, the last record in the database is the one edited and posted, regardless of the name selected in the list. I hope that makes sense. Any direction gratefully received. Jon ---------------------------------------------------------------------- clauslack · 2010-01-12 20:46 What is  UsersTableName.Text:=EditName;? For save a record Code: [Select]Dbf1.Edit;  Dbf1.FieldByName('nume_caj').asinteger:=number; Dbf1.FieldByName('fec_caja').AsDateTime:=dateVar; Dbf1.Post; Regards ---------------------------------------------------------------------- jonek · 2010-01-12 22:22 Thanks for your reply. It's the same as saying      UsersTable.FieldByName('Name').AsString:=EditName; ...which I have also tried, for thoroughness. Same result. The actual posting of the record is fine. It's the fact it's posting the wrong record that is the issue. ---------------------------------------------------------------------- jonek · 2010-01-20 19:26 Well, here's what I had to do to make it work. Code: [Select]begin   if UsersList.ItemIndex=-1 then Exit;   if not UsersTable.Locate('NAME',UsersList.Items[UsersList.ItemIndex],[]) then   begin     MessageDlg('Error 103',mtError,[mbOK],0);     Exit;   end;   EditName:=UsersTableName.Text;   repeat     if not InputQuery('Edit user', 'Re-enter the user''s name',EditName) then Exit;   until EditName<>'';   UsersTable.Locate('NAME',UsersList.Items[UsersList.ItemIndex],[]);   UsersTable.Edit;   UsersTableName.Text:=EditName;   UsersTable.Post;   BuildUsersList; end; I don't really understand why the second Locate line is necessary. However, moving on...