RAD Studio VCL Reference
ContentsIndex
PreviousUpNext
TField.DisplayName Property

Represents the name of the field for display purposes.

Pascal
property DisplayName: WideString;
C++
__property BSTR DisplayName;

Use DisplayName when displaying a string that represents the field to the user. For example, when raising an exception concerning the field, format an error string that includes the DisplayName to refer to the field. DisplayName is a read-only property. To change the value of DisplayName, use the DisplayLabel property. 

If DisplayLabel is defined, DisplayName is the same as DisplayLabel. Otherwise, DisplayName is the same as the FieldName property.  

C++ Examples: 

 

/*
This example requires a button, a test edit, and a populated
ClientDataSet.  Pipe the ClientDataSet through a DataSource
to a DGGrid or DBNavigator to control the current field.
Cast the data correctly according to the field type when
assigning to the test edit.
*/
void __fastcall TForm1::Button1Click(TObject *Sender)
{
  // Retrieve the "raw" data from Field1
  if (!CDS->Fields->Fields[0]->IsBlob(__classid(TField))) // GetData does not work for BLOB fields
  {
    void *MyBuffer = malloc(CDS->Fields->Fields[0]->DataSize);
    try
    {
      if (!CDS->Fields->Fields[0]->GetData(MyBuffer))
        MessageDlg(CDS->Fields->Fields[0]->DisplayName + "is blank.", mtInformation, TMsgDlgButtons() << mbOK,0);
      else
        // Do something with the data;
        Edit1->Text = (char *)MyBuffer; // for a stringfield
    }
    __finally
    {
      free(MyBuffer);
    }
  }
}

void __fastcall TForm1::FormCreate(TObject *Sender)
{
  CDS->LoadFromFile("../CDS.XML");
}

 

Delphi Examples: 

{
This example requires a button, a test edit, and a populated
ClientDataSet.  Pipe the ClientDataSet through a DataSource
to a DGGrid or DBNavigator to control the current field.
Cast the data correctly according to the field type when
assigning to the test edit.
}
procedure TForm1.Button1Click(Sender: TObject);
var MyBuffer: Pointer;
begin
{ Retrieve the "raw" data from Field1 }
with CDS.Fields[0] do
  begin
    if not IsBlob then { this does not work for BLOB fields }
    begin
      { Allocate space }
      MyBuffer:= GetMemory(DataSize);
      try
        if not GetData(MyBuffer) then
          MessageDlg(DisplayName + ' is NULL', mtInformation, [mbOK], 0)
        else
          { Do something with the data };
          Edit1.Text:= string(MyBuffer); // for a stringfield
      finally
        { Free the space }
        FreeMem(MyBuffer, DataSize);
      end;
    end;
  end;
end;

procedure TForm1.FormCreate(Sender: TObject);
begin
  CDS.LoadFromFile(gsAppPath + 'CDS.XML');
end;

 

Copyright(C) 2008 CodeGear(TM). All Rights Reserved.
What do you think about this topic? Send feedback!