User Tools

Site Tools


api:dk11:delphi:gislayervector.tgis_layervector.renamefield_string_string_integer_integer

Table of Contents

TGIS_LayerVector.RenameField method

DK11 for Delphi | GisLayerVector.TGIS_LayerVector.RenameField | Constructors | Fields | Methods | Properties | Events

Renames a field.

Available also on: .NET | Java | ActiveX | Python.

Syntax

// Delphi
public
  procedure RenameField(
    const _name : String;
    const _newname : String;
    const _width : Integer;
    const _decimal : Integer
  ); virtual;
// C++ Builder
public:
  virtual void RenameField(
    const UnicodeString _name,
    const UnicodeString _newname,
    const int _width,
    const int _decimal
  );

Parameters

Name Type Description
_name String name of field to be renamed
_newname String new name
_width Integer new width
_decimal Integer new decimal position

Remarks

Use this method to rename a field, which will be marked as changed and the final restructure will be performed upon save. UnRename can be performed by using RevertAll.

Example

Here is a simple procedure to add a field to a new layer or rename existing one.

Delphi

procedure MyClass.SaveInfo();
var
  i    : Integer ;
  cnt  : Integer ;
  ipos : Integer ;
  pfld : PGIS_FieldInfo ;
begin
  // check layer and shape
  if layerObj = nil then exit ;
  if shpObj   = nil then exit ;
 
  // let's count fields
  cnt := 0 ;
  for i:=0 to layerObj.Fields.Count-1 do begin
    if layerObj.FieldInfo(i)^.Deleted then continue ;
    inc( cnt ) ;
  end ;
 
  // we use stgEditedPart (TStringGrid) control to display and edit fields
  ipos := 0 ;
  for i:=1 to stgEditedPart.RowCount - 1 do begin
    if stgEditedPart.Cells[ 0, i ] = '' then exit ;
 
    while ( ipos < layerObj.Fields.Count ) do begin
      if not layerObj.FieldInfo(ipos)^.Deleted then break ;
      inc( ipos ) ;
    end ;
 
    // if new position, add a new field
    if cnt < i then
       layerObj.AddField( stgEditedPart.Cells[ 0, i ],TGIS_FieldType.String, 80, 0)
    else begin
      // else if existing changed, rename it and change a value
      pfld := layerObj.FieldInfo( ipos ) ;
      if CompareText( pfld^.NewName, stgEditedPart.Cells[ 1, i ]  ) <> 0 then
        layerObj.RenameField( pfld^.NewName,stgEditedPart.Cells[ 0, i ],
                              pfld^.Width,pfld^.Decimal
                            )
    end ;
  // remember changes in grid
    shpObj.SetField( stgEditedPart.Cells[ 0, i ],stgEditedPart.Cells[ 1, i ]) ;
    inc( ipos ) ;
  end ;
end ;
2022/11/16 01:22

Page Tools