vcl-cxdbedit-dot-tcxdbimage.md
Provides access to data binding settings.
property DataBinding: TcxDBEditDataBinding read; write;
| Type | Description |
|---|---|
| TcxDBEditDataBinding |
Stores data binding editor settings.
|
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.
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.
The following code example creates a BLOB field in a TdxMemData component and binds a TcxDBImage editor to the field:
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;
#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();
The following code example allows users to select and load an image file to the bound BLOB dataset field in a TdxMemData component:
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;
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