DBImage (Delphi)

From RAD Studio Code Examples
Jump to: navigation, search

Description

This example requires a TDBImage, a TClientDataSet and a TDataSource already on the form. A custom data set is created and a record is added to it, containing a sample image. The TDBImage control then displays the 'Image' field in the data source. The Proportional flag of the TDBImage control is set to True in order to make the sample image fit the bounds of the TDBImage.

Code

procedure TForm1.FormCreate(Sender: TObject);
begin
  ClientDataSet1.Active := False;
  with ClientDataSet1.FieldDefs do
  begin
    with AddFieldDef do
    begin
      DataType := ftString;
      Size := 20;
      Name := 'Name';
    end;
    with AddFieldDef do
    begin
      DataType := ftGraphic;
      Name := 'Image';
    end;
  end;

  DataSource1 := TDataSource.Create(Form1);
  DataSource1.DataSet := ClientDataSet1;

  ClientDataSet1.CreateDataSet;

  ClientDataSet1.Insert;
  ClientDataSet1.FieldByName('Name').Value := 'test';
  (ClientDataSet1.FieldByName('Image') as TGraphicField).LoadFromFile('flower.bmp');
  ClientDataSet1.Post;

  DBImage1.DataSource := DataSource1;
  DBImage1.Proportional := True;
  DBImage1.DataField := 'Image';
end;

Uses

Personal tools
Assistance