hua wrote:Hi guys,
Sometimes when maintaining legacy modules, I come across dbfs which have cryptic field names.
If I have a dbf with field name cod, otr1, otp1 is it possible to create a TDatabase object where the field name is more user friendly and mapped to the physical dbf?
I mean creating oDbf:EmployeeCode to map to field cod, oDbf:OTRate1 mapped to field otr1, oDbf:OTAmount1 mapped to field otp1, etc?
Thank you for any tip
TDatabase has this feature for many years. To be exact, from FWH 10.02 onwards.
oDbf:MapCol( cFieldName, cUserFriendlyName )
or
oDbf:MapCol( { { "fld1", "name1" }, .... { "fldN","nameN" } } )
Small Sample:
- Code: Select all Expand view
local oDbf
oDbf := TDatabase():Open( nil, "STATES", "DBFCDX", .T. )
oDbf:MapCol( "CODE", "StateCode" )
oDbf:MapCol( "NAME", "StateName" )
/*
// Alternatively, we can assign several fields together
oDbf:MapCol( { { "CODE", "StateCode" }, ;
{ "NAME", "StateCode" } } )
*/
? odbf:name, odbf:statename
oDbf:Edit()
XBROWSER oDbf
.