Insert/Edit/Delete methods

Posted in Databases

This example uses COUNTRY.DB database of DBDEMOS standard alias. To insert/update/delete record to/of/from database, you may use standard methods of Table component.

// Insert record
procedure TForm1.Button1Click(Sender: TObject);
begin
  Table1.InsertRecord(['A_My_Country', 
                       'A_My_Capital', 
                       'A_My_Continent', 
                       1,
                       1]);
end;

// Delete record
procedure TForm1.Button2Click(Sender: TObject);
begin
  Table1.Locate('NAME', 'A_My_Country', [loPartialKey]);
  Table1.Delete;
end;

// Update record
procedure TForm1.Button3Click(Sender: TObject);
begin
  with Table1 do
  begin
    Locate('NAME', 'A_My_Country', [loPartialKey]);
    Edit;
    FieldByName('NAME').AsString:='A_Your_Country';
    Post;
    Refresh;
  end;
end;