TFieldGetData (Delphi)
From RAD Studio Code Examples
Language:
Description
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.
Code
{$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;
Uses
- Data.DB.TBCDField ( fr | de | ja )
- Data.DB.TBooleanField ( fr | de | ja )
- Data.DB.TBytesField ( fr | de | ja )
- Data.DB.TDateField ( fr | de | ja )
- Data.DB.TDateTimeField ( fr | de | ja )
- Data.DB.TField.DataSize ( fr | de | ja )
- Data.DB.TFloatField ( fr | de | ja )
- Data.DB.TFMTBCDField ( fr | de | ja )
- Data.DB.TIntegerField ( fr | de | ja )
- Data.DB.TLargeintField ( fr | de | ja )
- Data.DB.TSmallintField ( fr | de | ja )
- Data.DB.TSQLTimeStampField ( fr | de | ja )
- Data.DB.TStringField ( fr | de | ja )
- Data.DB.TTimeField ( fr | de | ja )
- Data.DB.TVarBytesField ( fr | de | ja )
- Data.DB.TWordField ( fr | de | ja )
- Data.DB.TField.GetData ( fr | de | ja )
- Data.DB.TBlobField.IsBlob ( fr | de | ja )
- Data.DB.TField.DisplayName ( fr | de | ja )
- System.GetMemory ( fr | de | ja )