Back to Devexpress

TcxDBImage.DataBinding Property

vcl-cxdbedit-dot-tcxdbimage.md

latest4.8 KB
Original Source

TcxDBImage.DataBinding Property

Provides access to data binding settings.

Declaration

delphi
property DataBinding: TcxDBEditDataBinding read; write;

Property Value

TypeDescription
TcxDBEditDataBinding

Stores data binding editor settings.

|

Remarks

You can use DataBinding.DataSource and DataBinding.DataField properties to bind the data-aware image editor to data.

Refer to the TcxDBEditDataBinding class description for detailed information on all available options.

Important

Ensure that the bound dataset field contains image data; otherwise, an error may occur.

Blob Fields and Supported Image Formats

We recommend that you set the Properties.GraphicClass property to TdxSmartImage to ensure that the TcxDBImage editor supports the following image formats:

BMP | EMF | GIF | JPEG | PNG | TIFF | WMFSupport for these image formats relies on corresponding native encoders from the Windows Imaging Component (WIC).SVGDevExpress controls use our own SVG engine implementation. Refer to the following topic for detailed information on supported SVG elements and their attributes: SVG Image Support.

Code Examples

Bind to Data

The following code example creates a BLOB field in a TdxMemData component and binds a TcxDBImage editor to the field:

delphi
uses
  dxGDIPlusClasses; // Declares the TdxSmartImage class
// ...
var
  AFieldDef: TFieldDef;
begin
  if dxMemData1.Active then
    dxMemData1.Close;
  AFieldDef := dxMemData1.FieldDefs.AddFieldDef;
  AFieldDef.Name := 'MyImageField';
  AFieldDef.DataType := ftBlob;
  AFieldDef.CreateField(dxMemData1);
  DataSource1.DataSet := dxMemData1;
  DataSource1.Enabled := True;
  cxDBImage1.DataBinding.DataSource := DataSource1;
  cxDBImage1.DataBinding.DataField := 'MyImageField';
  cxDBImage1.Properties.GraphicClass := TdxSmartImage; // Selects the universal container
  dxMemData1.Open;
end;
cpp
#include "dxGDIPlusClasses.hpp" // Declares the TdxSmartImage class
// ...
  TFieldDef *AFieldDef;
  // ...
  if(dxMemData1->Active) { dxMemData1->Close(); }
  AFieldDef = dxMemData1->FieldDefs->AddFieldDef();
  AFieldDef->Name = "MyImageField";
  AFieldDef->DataType = ftBlob;
  AFieldDef->CreateField(dxMemData1);
  DataSource1->DataSet = dxMemData1;
  DataSource1->Enabled = true;
  cxDBImage1->DataBinding->DataSource = DataSource1;
  cxDBImage1->DataBinding->DataField = "MyImageField";
  cxDBImage1->Properties->GraphicClass = __classid(TdxSmartImage); // Selects the universal container
  dxMemData1->Open();

Load an Image from a File

The following code example allows users to select and load an image file to the bound BLOB dataset field in a TdxMemData component:

delphi
var
  ADataBinding: TcxDBEditDataBinding;
  AField: TBlobField;
begin
  ADataBinding := cxDBImage1.DataBinding;
  dxOpenPictureDialog1.Execute(Handle);
  if ((dxOpenPictureDialog1.FileName = '') or (not ADataBinding.CanModify)) then Exit;
  dxMemData1.DisableControls;
  try
    dxMemData1.Append;
    AField := ADataBinding.Field as TBlobField;
    AField.LoadFromFile(dxOpenPictureDialog1.FileName);
    dxMemData1.Post;
  finally
    dxMemData1.EnableControls;
  end;
end;
cpp
TcxDBEditDataBinding *ADataBinding;
  TBlobField *AField;
  // ...
  ADataBinding = cxDBImage1->DataBinding;
  dxOpenPictureDialog1->Execute(Handle);
  if((dxOpenPictureDialog1->FileName == "") || (!ADataBinding->CanModify())) { return; }
  dxMemData1->DisableControls();
  try
  {
    dxMemData1->Append();
    AField = dynamic_cast<TBlobField*>(ADataBinding->Field);
    AField->LoadFromFile(dxOpenPictureDialog1->FileName);
    dxMemData1->Post();
  }
  __finally
  {
    dxMemData1->EnableControls();
  }

See Also

TcxDBImage Class

TcxDBImage Members

cxDBEdit Unit