To delete a record, retrieve the record to be deleted using one of the search functions discussed in Selecting Records, then call the TDataSet Delete method. It is not necessary to set the fields, except when this is required to retrieve the record (Find method, for instance). The following sequence shows the first record being deleted.
Note that the first record is retrieved without checking which index is used. The searching methods will be discussed in the topic “Selecting Records”. In the current topic, the update or delete is the central point of interest.
The following excerpts implement this sequence at run time:
Delphi Example
procedure Form1.DeleteRecord();
begin
try
CtTable1.Table := 'MyTable';
CtTable1.Database := CtDatabase1;
CtTable1.Active := True;
CtTable1.First();
CtTable1.Delete();
except
on E : ECtError do
Application.ShowException(E);
end;
end;
C++ Example
void Form1:: DeleteRecord()
{
try
{
CtTable1->Table = "MyTable";
CtTable1->Database = CtDatabase1;
CtTable1->Active = true;
CtTable1->First;
CtTable1->Delete;
}
catch (ECtError& E)
{
Application->ShowException(&E);
}
}
Use the following procedure to add new data to a c-tree Plus table using the FairCom DB API methodology:
Delphi Example
procedure Form1.AddRecord();
var
rec1 : TCtRecord;
begin
try
rec1:=TCtRecord.Create;
rec1.Allocate(CtTable1);
rec1.Clear;
rec1.SetFieldAsString(0,'Bob Nash');
rec1.SetFieldAsInteger(1, 46);
rec1.SetFieldAsString(2,'2300');
rec1.BeginTransaction;
rec1.Write;
rec1.CommitTransaction;
except
on E : ECtError do
Application.ShowException(E);
end;
end;
C++ Example
void Form1:: AddRecord()
{
TCtRecord* rec1;
try
{
rec1 = new TCtRecord();
rec1->Allocate(CtTable1);
rec1->Clear();
rec1->SetFieldAsString(0,"Sverner Knight");
rec1->SetFieldAsUnsigned(1, 52);
rec1->BeginTransaction();
rec1->Write();
rec1->CommitTransaction();
}
catch (ECtError& E)
{
Application->ShowException(&E);
}
}