Calculate all DBGrid Rows 'Cena' (price).
'Cena' AsString;
The result written to Edit.
Delphi-Quellcode:
function Calculate_(table: TABSTable; Field: string):string;
var
celkem: string;
tpRunTotal: string;
begin
result := '0';
tpRunTotal := '0,00';
with Table do
begin
First;
while not EOF do
begin
tpRunTotal := FloatToStr((StrToFloat(tpRunTotal) + (StrToFloat(Table.FieldByName(field).AsString))));
celkem := FormatFloat('0.00', StrToFloat(tpRunTotal));
result := celkem;
Next;
end;
end;
end;
Example:
dm := TDataModule;
prodej_distributor := TABSTable;
Edit1.Text := Calculate_(dm.prodej_distributor,'Cena');