After the unit price and the number of input, movement in any direction in the number of cells (vertical and horizontal), the amount can be calculated automatically. How to achieve?
DBGridEh how to calculate the amount based on the unit price and quantity?
Guess you like
Origin www.cnblogs.com/jijm123/p/11701080.html
Recommended
Ranking
Procedure CalcMoney (Sender: of TField);
the begin
IF (DataSet.State in dsEditModes) and (. Not DataSet.FieldByName ( 'Qty') IsNull) and (Not the DataSet .FieldByName ( 'Price') IsNull).
the then
DataSet.FieldByName ( 'Money') AsCurrency:... = DataSet.FieldByName ( 'Qty') AsFloat * DataSet.FieldByName ( 'Price') AsCurrency;
End; then the data AfterOpen BeforeClose set of events and added the following code:
AfterOpen:
. DataSet.FieldByName ( 'Qty') the OnChange: = CalcMoney;
DataSet.FieldByName ( 'Price') the OnChange:. = CalcMoney;
BeforeClose;
DataSet.FieldByName ( 'Qty' ) .OnChange: = Nil;
DataSet.FieldByName('Price').OnChange := Nil;
begin
if (Sender.DataSet.State in dsEditModes) and (not Sender.DataSet.FieldByName('Counts').IsNull)
and (not Sender.DataSet.FieldByName('Price').IsNull)
then
Sender.DataSet.FieldByName('Money').AsCurrency := Sender.DataSet.FieldByName('Counts').AsFloat * Sender.DataSet.FieldByName('Price').AsCurrency;
end;改成这个之后,编译时提示:
E2009 Incompatible types:'method pointer and regular procedure'
begin
if (Sender.DataSet.FieldByName('Counts').IsNull) then
Sender.DataSet.FieldByName('Counts').AsFloat := 0;
if (Sender.DataSet.FieldByName('Price').IsNull) then
Sender.DataSet.FieldByName('Price').AsCurrency := 0;
if (Sender.DataSet.State in dsEditModes) and (not Sender.DataSet.FieldByName('Counts').IsNull)
and (not Sender.DataSet.FieldByName('Price').IsNull)
then
Sender.DataSet.FieldByName('Money').AsCurrency := Sender.DataSet.FieldByName('Counts').AsFloat * Sender.DataSet.FieldByName('Price').AsCurrency;
end;我试了,这样可以实现。