Formatting numeric attributes in ECO IV
Let me start off by saying that the contents of this blog post is derived from a technique shown to me today by Jose Maria Sanmartin. Full credit should go to him for providing the meat in this particular sandwich.
Normally when data-binding to ECO attributes in VCL.NET there doesn’t appear to be any opportunity to format the output. This is less than ideal if you are displaying things such as currency data to the user. In a standard VCL database application, you could use the DisplayFormat and EditFormat properties of the relevant TField descendant to control this. While these properties are not surfaced at design-time by the ECO handle components, it is still possible to set them. Here is some code I use in my application which allows me to do this :-
procedureContractManagerEcoSpace.FormatNumericField(AHandle: TElementHandle;constAFieldName, ADisplayFormat:string; AEditFormat:string='');varField: TADONETNumericField;beginField := AHandle.FieldByName(AFieldName)asTADONETNumericField; Field.DisplayFormat := ADisplayFormat; Field.EditFormat := AEditFormat;end;
Because all ECO handle components ultimately descend from TElementHandle, the above routine can be used with TExpressionHandle, TReferenceHandle and TOclPSHandle references. And here is code demonstrating how to consume this method :-
procedureTInvoiceForm.SetDisplayFormats;constcnCurrencyFormat ='$###,###,##0.00';beginEcoSpace.FormatNumericField(rhCurrentInvoice,'BillableAmountExTax', cnCurrencyFormat); EcoSpace.FormatNumericField(rhCurrentInvoice,'BillableAmountInclTax', cnCurrencyFormat); EcoSpace.FormatNumericField(rhCurrentInvoice,'GSTAmount', cnCurrencyFormat); EcoSpace.FormatNumericField(ehWorkItems,'BillableAmountExTax', cnCurrencyFormat); EcoSpace.FormatNumericField(ehWorkItems,'BillableAmountInclTax', cnCurrencyFormat); EcoSpace.FormatNumericField(ehWorkItems,'GSTAmount', cnCurrencyFormat);end;
Once again, thanks to Jose Maria Sanmartin for bringing this technique to my attention.
Share This | Email this page to a friend
Posted by David Clegg on September 23rd, 2007 under .NET, ECO |

RSS Feed

Leave a Comment