Object的使用技巧
当对象转换为object之后可以调用任一方法,而且编译器不会报错。这样有利全用args.caller()传递对象到目标后,在目标方利用object转换后调用caller中的方法
boolean useConvertableLookup(Object caller)
{
InventMovement inventMovement;
InventTableModule inventTableModule;
PriceDiscTable priceDiscTable;
SuppItemTable suppItemTable;
fieldId itemIdField;
;
if (!element.args() || !element.args().caller())
return false;
if (caller.name() == formstr(UnitConversion))
{
otherUnit = caller.otherUnit();
selectedItemId = caller.selectedItemId();
if (selectedItemId && !otherUnit)
this.buildConversionConvertable();
else
this.buildConvertable();
return true;
}
if (caller.name() == formstr(InventOnHandMovement) ||
caller.name() == formstr(InventOnHandItem) ||
caller.name() == formstr(InventOnHandReserve) ||
caller.name() == formstr(WMSPickingLinePick))
{
otherUnit = caller.otherUnit();
selectedItemId = caller.selectedItemId();
this.buildConvertable();
return true;
}
if (element.args().dataset())
{
switch(element.args().dataset())
{
case tablenum(InventTableModule):
inventTableModule = element.args().record();
switch(inventTableModule.ModuleType)
{
case ModuleInventPurchSales::Invent:
return false;
default:
selectedItemId = inventTableModule.ItemId;
otherUnit = InventTable::find(selectedItemId).inventUnitId();
this.buildConvertable();
return true;
}
case tablenum(PriceDiscTable):
priceDiscTable = element.args().record();
if (priceDiscTable.ItemCode != TableGroupAll::Table)
return false;
selectedItemId = priceDiscTable.ItemRelation;
if (!selectedItemId)
return false;
otherUnit = InventTable::find(selectedItemId).inventUnitId();
this.buildConvertable();
return true;
case tablenum(SuppItemTable):
suppItemTable = element.args().record();
if (suppItemTable.ItemCode != TableGroupAll::Table)
return false;
selectedItemId = suppItemTable.ItemRelation;
if (!selectedItemId)
return false;
otherUnit = InventTable::find(selectedItemId).inventUnitId();
this.buildConvertable();
return true;
default:
itemIdField = fieldname2id(element.args().dataset(),fieldstr(InventTable,ItemId));
if (itemIdField)
{
selectedItemId = element.args().record().(itemIdField);
if (!selectedItemId)
return false;
otherUnit = InventTable::find(selectedItemId).inventUnitId();
this.buildConvertable();
return true;
}
break;
}
}
if (element.args().dataset())
{
inventMovement = InventMovement::constructNoThrow(element.args().record());
if (inventMovement)
{
selectedItemId = inventMovement.itemId();
otherUnit = InventTable::find(selectedItemId).inventUnitId();
this.buildConvertable();
return true;
}
}
return false;
}