ADO - Summary Sheet
ADO - Summary Sheet
Format of working with one of the fields in a table: sName := tableName[‘field name’];
BASIC FRAMEWORKS:
Display All To display all the records in a database table. tblBikes.First;
While tblBikes.EOF = False do
Begin
Casting of data types is necessary. red.lines.add(tblBikes[‘Name’] + #9 +
(FloatToStrF(tblBikes[‘Price’]);
NB: .Next moves to the next record. Will result tblBikes.Next;
in an infinite loop if left out. End;
Alternative loop Instead of a While, you could use a For Loop tblBikes.First;
method For iLoop := 1 to tblBikes.Recordcount do
Begin
red.lines.add(tblBikes[‘Name’]);
tblBikes.Next;
End;
Add records NO loop when adding. tblBikes.Append;
(Append/Insert) tblBikes[‘Name’] := edtBikeName.text;
Two methods (you may use any): tblBikes[‘Price’] := StrToFloat(edtPrice.text);
Append adds to the end of the table. tblBikes.Post;
Delete, edit Use a boolean flag to stop the loop as soon as a tblBikes.First;
ONE record particular record is deleted or edited. Bfound := false;
(depends on the question). While (tblBikes.eof = false) AND (bfound = false) do
Example is of a delete, but the same principle is Begin
to be followed for edit. IF sFind = tblBikes[‘name’] then
Begin
tblBikes.Delete;
bFound := true;
End
ELSE tblBikes.Next;
end;
ONCLICK When a table is displayed in a dgGrid, EXAMPLE of displaying the ACTIVE record:
The user can select a record by clicking on it. pnlBikeName.caption := tblBikes[‘Names’] ;
pnlBikePrice.caption := FloatToStr(tblBikes[‘Price’]);
That record is then the ACTIVE record,
And can be displayed, edited or deleted EXAMPLE of deleting the ACTIVE record:
WITHOUT having to search for it (using a loop) IF MessageDLG(‘You want to delete: ‘+tblBikes[‘names’],
mtConfirmation, mbYesNo, 0) = mrYes
The active record will have an arrow in front of it. Then begin
tblBikes.Delete;
ALWAYS ask for confirmation when editing showmessage(‘deleted’);
or deleting by using a messagedlg or end;
inputbox.
Double Tables Based on the question, you might have to work //first table - primary table
with two tables at the same time. tblBikesSuppliers.First;
E.g. BikesSuppliers and BikesInfo While tblBikesSuppliers.EOF = false do
Begin
Question: rSum := 0; //new sum for each supplier
Determine the total Bike prices for each Bike sSupplierID := tblBikesSuppliers[‘SuppID’]; //primaryKey
supplier.
Prices from BikesInfo, //second table - inside loop
Supplier Name from BikesSuppliers tblBikes.First; //NB → bring filepointer to top
While tblBikes.Eof = False do //inside loop finds all
//prices for that supplier
Begin
If sSupplierID = tblBikes[‘SupplierID’]//foreignKey
Then rSum := rSum + tblBikes[‘price’];
End; //inside loop
red.lines.add(tblBikesSuppliers[‘supplierName’] + #9+
FloatToStr(rSum) );
End; //outside loop