Manage() provides data management functionality for your application and/or process.
Below is the code for Manage():
procedure TForm1.Manage;
begin
Add_CustomerMaster_Records;
Display_Records;
end;
procedure TForm1.btnUpdateClick(Sender: TObject);
begin
Update_CustomerMaster_Record;
Display_Records;
end;
procedure TForm1.Add_CustomerMaster_Records();
var
counter : integer;
begin
try
Delete_Records(TabCustMast);
for counter := 1 to 4 do
begin
// clear the record buffer
TabCustMast.ActiveRecord.Clear;
// populate the record buffer
TabCustMast.ActiveRecord.SetFieldAsString(0, cm_data[counter, 1]);
TabCustMast.ActiveRecord.SetFieldAsString(1, cm_data[counter, 2]);
TabCustMast.ActiveRecord.SetFieldAsString(2, cm_data[counter, 3]);
TabCustMast.ActiveRecord.SetFieldAsString(3, cm_data[counter, 4]);
TabCustMast.ActiveRecord.SetFieldAsString(4, cm_data[counter, 5]);
TabCustMast.ActiveRecord.SetFieldAsString(5, cm_data[counter, 6]);
TabCustMast.ActiveRecord.SetFieldAsString(6, cm_data[counter, 7]);
// write the record
TabCustMast.ActiveRecord.Write;
end;
except
on E : ECtError do Application.ShowException(E);
end;
end;
procedure TForm1.Delete_Records(ATable : TCtTable);
begin
try
while ATable.ActiveRecord.First do
begin
ATable.ActiveRecord.Delete;
end;
except
on E : ECtError do Application.ShowException(E);
end;
end;
procedure TForm1.Update_CustomerMaster_Record;
var
str : string;
begin
try
str := '1003';
TabCustMast.Lock(CTLOCK_WRITE_BLOCK);
TabCustMast.ActiveRecord.Clear;
TabCustMast.ActiveRecord.SetFieldAsString(0, str);
if TabCustMast.ActiveRecord.Find(CTFIND_EQ) then
begin
str := 'KEYON DOOLING';
TabCustMast.ActiveRecord.SetFieldAsString(4, str);
TabCustMast.ActiveRecord.Write;
end;
Application.MessageBox('Press any key to unlock record', 'Warning');
TabCustMast.Unlock;
except
on E : ECtError do
begin
Application.ShowException(E);
end;
end;
end;
procedure TForm1.Display_Records;
var
ARow : integer;
ACol : integer;
AField : string;
begin
StringGrid1.RowCount := 2;
// display the field names
for ACol := 0 to 4 do
StringGrid1.Cells[ACol, 0] := TabCustMast.Fields[ACol].Field;
// read all fields and display on grid
ARow := 0;
// lock records for reading
if TabCustMast.ActiveRecord.First then
repeat
if ARow > 0 then
StringGrid1.RowCount := StringGrid1.RowCount + 1;
for ACol := 0 to 4 do
begin
TabCustMast.ActiveRecord.GetFieldAsString(ACol, AField);
StringGrid1.Cells[ACol, (ARow + 1)] := AField;
end;
inc(ARow);
until TabCustMast.ActiveRecord.Next = false;
end;