RAD Studio VCL Reference
ContentsIndex
PreviousUpNext
TFMTBCDField Class

TFMTBCDField represents a binary-coded decimal (BCD) field in a dataset.

Pascal
TFMTBCDField = class(TNumericField);
C++
class TFMTBCDField : public TNumericField;

TFMTBCDField encapsulates the fundamental behavior common to binary-coded decimal (BCD) fields. BCD values provide greater precision and accuracy than floating-point numbers. BCD fields are often used for storing and manipulating monetary values.  

The IDE uses two different field types for representing BCD fields: TFMTBCDField and TBCDField. TFMTBCDField uses a true BCD value (TBCD) to store and manipulate BCD values. This gives greater precision and accuracy than the currency type used by TBCDField objects, but results in somewhat slower performance. If your application does not require more than 4 decimal places or 20 significant digits, you may want to use TBCDField instead to take advantage of its better performance. 

If you use the Fields editor at design time to create a persistent field component for the BCD field, you can access it by name at runtime. When using dynamic field components, you can access the TFMTBCDField instance using the dataset's Fields property or FieldByName method.  

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.
}

{$IFNDEF UNICODE}
uses SwSystem;
{$ENDIF}

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(PAnsiChar(MyBuffer)); // for a stringfield
      finally
        { Free the space }
        FreeMem(MyBuffer, DataSize);
      end;
    end;
  end;
end;

procedure TForm1.FormCreate(Sender: TObject);
begin
{$IFDEF UNICODE}
  CDS.LoadFromFile(GetCurrentDir + '\CDS.XML');
{$ELSE}
  CDS.LoadFromFile(gsAppPath + 'CDS.XML');
{$ENDIF}
end;

 

Copyright(C) 2009 Embarcadero Technologies, Inc. All Rights Reserved.
What do you think about this topic? Send feedback!