Language Reference Guide : System Classes : FieldObject Class
 
Share this page          
FieldObject Class
Note:  The FieldObject class is used for classification only, not for display.
This class is the highest-level object for all form and menu fields. It contains the information needed to associate the field, if named, with a frame-local variable or with a same-name attribute in a user class or system class object. The field will automatically display the variable or attribute value.
Most of the FieldObject attributes are set when you specify the properties of the field in Workbench. If you create frames dynamically at runtime, then you must set these attributes from your 4GL script. For an example of dynamic frame creation, see the Programming Guide.
The FieldObject inner margin attributes apply only to the EntryField class and its subclasses (FreeTrim and BoxTrim): the default inner margin values for fields belonging to these classes are are all 2 pixels, but you may set specific inner margins for them using the BottomInnerMargin, LeftInnerMargin, RightInnerMargin, and TopInnerMargin attributes.
One important attribute defined at the FieldObject level is the HasDataChanged attribute. This indicates whether the data in your form has been changed by user interaction with the form. It can also be set from your 4GL script if, for instance, the data changes because of database access. If the attribute is TRUE for a field on a form, this might be an indication that a database or file access must be done to update the stored version of the data.
Accessing a field or its value at runtime
You may access the variable displayed by a field at runtime two ways in your 4GL code:
If the field's Name attribute is set (for example, to 'birthplace'), the name applies to the value variable (not the field), so you would assign or read the value using the name:
birthplace = 'London';
If the field's Name attribute is not set, but you have a reference to the field (for example, 'myField'), you can use the FieldObject methods SetFieldValue and GetFieldValue:
myField.SetFieldValue(value='London');
You may access a field at runtime in various ways in your 4GL code:
If the field's Name attribute is set in Workbench (for example, to 'birthplace'), you can use the Field keyword or the CreateDynExpr method to access that field and its properties:
myField = field(birthplace); //where myField is a 4GL variable you declared, of type FieldObject
field(birthplace).BgColor = CC_GREEN; //turns the field background green
myField.BgColor = CC_GREEN; //also turns the field background green
name = 'birthplace';
myDynExpr = curframe.Scope.CreateDynExpr(string=name); //where myDynExpr is a 4GL variable, of type DynExpr
myDynExpr.GetValue(value=Byref(myField));
myField.BgColor = CC_GREEN;
If the field's Name attribute is set (even if set at runtime), you may also use the methods FieldByName, FieldByFullName, and FieldsByProperty to access that field and its properties:
name = 'birthplace';
fullname = 'employee.birthplace';
myField = curframe.TopForm.FieldByName(name=name);
myField = curframe.TopForm.FieldByFullName(fullname=fullname);
fields = curframe.FieldsByProperty(
attributename='name', searchstring=name); //fields is array of FormField
myField = fields[1];
myField.BgColor = CC_GREEN;
If the field's Name attribute is not set, you can still use the method FieldsByProperty to access that field and its properties, provided it has some identifying property (for example, a ClientText value of 'probable place of birth'):
identifyinglabel = 'probable place of birth';
fields = curframe.FieldsByProperty(attributename='clienttext', searchstring=identifyinglabel);
myField = fields[1];
myField.BgColor = CC_GREEN;
Note:  An important consideration regarding use of the Field keyword is that the name element is not substitutable, making it inflexible when you are developing code. If you are applying the same change to 10 different fields, you must write 10 different field statements; you cannot iterate a single field statement loop through a list of names.
All the other techniques mentioned previously are substitutable.
Inherits From
Object Class
Inherited By
ActiveField
AnalogField
BarField
BoxTrim
ButtonField
ChoiceField
ColumnField
CompositeField
ControlButton
DisplayForm
EllipseShape
EntryField
EnumField
ExtObjField
FlexibleForm
FormField
FrameForm
FreeTrim
ImageField
ImageTrim
ListField
ListviewField
MainBar
MatrixField
MenuBar
MenuButton
MenuField
MenuGroup
MenuItem
MenuList
MenuSeparator
MenuStack
MenuToggle
OptionField
OptionMenu
PaletteField
PopupButton
RadioField
RectangleShape
ScalarField
ScrollBarField
SegmentShape
ShapeField
SliderField
StackField
SubForm
TabBar
TabField
TabFolder
TableField
TabPage
ToggleField
TreeviewField
ViewportField
Attributes
BgColor
BottomInnerMargin
ClientText
ControlField
DataType
DefaultString
DefaultValue
FgColor
FullName
HasDataChanged
IsNullable
LeftInnerMargin
Name
ParentExec
RightInnerMargin
Script
TaggedValues
TopInnerMargin
Methods
FetchTaggedValue
FindTag
GetFieldValue
GetTaggedValues
GetTagText
GetTagValue
IsDescendantOf
RemoveTaggedValue
SetFieldValue
SetTaggedValue
UpdValue
WhichTablefield