2. Then, you can use the following function to sum, for example, values in the AField filed in all the rows selected (in the Table1, DBGrid1)!
~~~~~~~~~~~~~~~~~~~~~~~~~
function SUMSomething: Float;
var
i: Integer;
Sum: Currency;
begin
Sum := 0;
for i := 1 to DBGrid1.SelectedRows.Count do
begin
Table1.GotoBookMark
(Pointer(DBGrid1.SelectedRows.Items[i-1])) ;
{
The TDBGrid component keeps all the
selections as Bookmarks in a
TStringList, and all the Bookmarks
must be converted to a Pointer
(what they really are) before using it.
}
Sum := Sum +
Table1.FieldByName('AField').AsFloat;
end;
Result := Sum;
end;
~~~~~~~~~~~~~~~~~~~~~~~~~
Here are some more DBGrid related articles and tutorials: DBGrid to the Max
Delphi tips navigator:
» Associate filetype (extension) with your application
« Open an applet from the Control Panel

