Ins records of different length

Posted in Databases

If you want to use one function to insert records into different tables, then you may use open-array parameters.

procedure InsertRec(const S: array of const);
begin
  Form1.Table1.AppendRecord(S);
end;

procedure TForm1.Button1Click(Sender: TObject);
begin
  Table1.Active:=False;
  Table1.Tablename:='Animals.dbf';
  Table1.Active:=True;
  InsertRec(['MyFish', 3, 5, 'MyAquarium']);
end;

procedure TForm1.Button2Click(Sender: TObject);
begin
  Table1.Active:=False;
  Table1.Tablename:='Clients.dbf';
  Table1.Active:=True;
  InsertRec(
    ['MyLastName', 'MyFirstName', 100, 'MyAddress', 'MyTown']);
end;