User Tools

Site Tools


api:dk11:delphi:gisfieldrules.tgis_fieldrule

TGIS_FieldRule class

DK11 for Delphi | GisFieldRules.TGIS_FieldRule | Classes | Constructors | Methods | Properties

Class responsible for complete rule based editing of the attribute field.

Available also on: .NET | Java | ActiveX.

Syntax

// Delphi
type
  TGIS_FieldRule = class
  end;
// C++ Builder
class PASCALIMPLEMENTATION TGIS_FieldRule

Constructors

Inherited Overrides Protected
Name Visibility Description
Create public Create an object.
Destroy public Destroy an object.

Methods

Inherited Overrides Protected
Name Visibility Description
Check public Check value against all formulas.
ResolveGet public Resolve value in a meaning of reading it form a layer.
ResolveSet public Resolve value in a meaning of saving it to a layer.

Properties

Inherited Protected
Name Visibility Description
Caption public Field caption.
LongName public Field long name (w/o taking care of file format limits).
Modified public True if rules were modified.
ValueAliases public List of all filed aliases.
ValueChecks public List of all checks associated the the filed.
ValueFormat public Value format specifier like in printf.
Values public List of all allowed values.

Example

Delphi

1. Create an alias for value 'Tom' of first field :

var
  r   : TGIS_FieldRule ;
  fld : TGIS_FieldInfo ;
begin
  fld := layer.FieldInfo(0) ;
  r := TGIS_FieldRule.Create ;
  r.ValueAliases.Aliases.Add( TGIS_FieldValueAlias.Create( 'Tommy', 'Tom' ) ) ;
  fld.Rules := r ;
end ;

2. Create a “not null” check for a value after editing :

var
  r   : TGIS_FieldRule ;
  fld : TGIS_FieldInfo ;
begin
  fld := layer.FieldInfo(0) ;
  r := TGIS_FieldRule.Create ;
  r.ValueChecks.Checks.Add(
    TGIS_FieldValueCheck.Create( TGIS_FieldValueCheckMode.AfterEdit,
                                 TGIS_FieldValueCheckFormula.Required,
                                 '',
                                 'Cannot be null'
                                )
  ) ;
  fld.Rules := r ;
end ;

3. Create a default value for a field :

var
  r   : TGIS_FieldRule ;
  fld : TGIS_FieldInfo ;
begin
  fld := layer.FieldInfo(0) ;
  r := TGIS_FieldRule.Create ;
  r.Values.DefaultValue := 'unknown' ;
  fld.Rules := r ;
end ;

4. Create a list of available values for a field :

var
  r   : TGIS_FieldRule ;
  fld : TGIS_FieldInfo ;
begin
  fld := layer.FieldInfo(0) ;
  r := TGIS_FieldRule.Create ;
  r.Values.Mode := TGIS_FieldValuesMode.SelectList ;
  r.Values.Items.Add( 'Ala'  ) ;
  r.Values.Items.Add( 'Tom'  ) ;
  r.Values.Items.Add( 'Boby' ) ;
  fld.Rules := r ;
end ;

5. Create a validator of a field value :

var
  r   : TGIS_FieldRule ;
  fld : TGIS_FieldInfo ;
begin
  fld := layer.FieldInfo(0) ;
  r := TGIS_FieldRule.Create ;
  r.ValueChecks.Checks.Add(
    TGIS_FieldValueCheck.Create( TGIS_FieldValueCheckMode.AfterEdit,
                                 TGIS_FieldValueCheckFormula.Regex,
                                 '[a-zA-Z0-9_.+-]+@[a-zA-Z0-9-]+\.[a-zA-Z0-9-.]+',
                                 'Invalid email'
                                )
  ) ;
  fld.Rules := r ;
end ;

6. Create a value formatter that can be used in attributes control to display e.g. '10 cm' :

var
  r   : TGIS_FieldRule ;
  fld : TGIS_FieldInfo ;
begin
  fld := layer.FieldInfo(0) ;
  r := TGIS_FieldRule.Create ;
  r.ValueFormat := '%s cm' ;
  fld.Rules := r ;
end ;

7. Save field rules to a file :

  TGIS_FieldRulesOperations.SaveFldx( 'myrules' + GIS_FLDX_EXT, layer ) ;

8. Load field rules from a file :

  TGIS_FieldRulesOperations.ParseFldx( 'myrules' + GIS_FLDX_EXT, layer ) ;

References

2020/05/26 12:33

Page Tools