Subject Showing calculated field in grid
Author rihoe
Hi!

I have grid with 3 columns: product, measuring unit, quantity.
Measuring unit is calculated column.
I use LookupCombo to select products. After product is selected, I
want to automatically show the corresponding unit. Then the user can
enter the quantity.
Sample:
Milk, liter, 5
Meat, kg, 3

Field calculation works OK only after I save record, but I want to
show unit immediately after user changes product selection. In IBO3.6
I used OnValidateField for that and it worked OK.

Now I'm using BCB5 with latest IBO4 and I'm having problems. When I
change quantity field value the OnValidate is called for all fields
(also for PRODUCT_ID). The end result is that I can't change
quantity. When I leave the row, it changes right back to original
value. But I can change product!

Maybe (probably) I'm doing something wrong. Any better ideas how to
change unit field immediately after product changes?




Code sample follows:

void __fastcall TFRetseptid::QDetailCalculateField(TIB_Statement
*Sender,
TIB_Row *ARow, TIB_Column *AField)
{
if(AField->FieldName=="UNIT")
{ DSQLYhik->Prepare();
DSQLYhik->Params->Columns[0]->Clear( ) ;
DSQLYhik->Params->Columns[0]->AsInteger=ARow->ByName
("PRODUCT_ID")->AsInteger;
DSQLYhik->Execute();
AField->AsString=DSQLYhik->Fields->Columns[0]-
>AsString;
DSQLYhik->Unprepare();
}

}
//--------------------------------------------------------------------
-------

void __fastcall TFRetseptid::QDetailValidateField(TIB_Statement
*Sender,
TIB_Row *ARow, TIB_Column *AField)
{
if(AField->FieldName=="PRODUCT_ID")
QDetail->CalculateFields();
}