Save GRID data with images

Hello


I would like to save GRID to BIN file. The grid has images in one cell. 

So I call SaveToBinFile() but when loading back using LoadFromBinFile() images are not loaded back. When I looked to AdvGrid.pas SaveToBinFile call SaveRectToBinStream and here it look like that inside this function it is testing if CellTypes has graphics. So I suppose that it should save also IMAGES. Or Is there another easy way to save all cell datas with objects like images?

Thanks in advance.

Radim


Please inform what exact image type/cell type you use. Image list images, bitmaps, picture, file referenced images, HTML invoked images, BitmapContainer referenced images,... ?

Dear Bruno,


Thanks for quick response. It looks that cell type is exactly Picture. I tested it by calling AdvStringGrid.CellTypes[4, 1] and it reports 'ctPicture'

Radim

I have retested this here with following code and this works fine to use a binary stream to copy a cell with a picture from one grid to another grid:


type
  TForm3 = class(TForm)
    AdvStringGrid1: TAdvStringGrid;
    AdvStringGrid2: TAdvStringGrid;
    Button1: TButton;
    procedure FormCreate(Sender: TObject);
    procedure Button1Click(Sender: TObject);
    procedure FormDestroy(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
    pic: TPicture;
  end;

var
  Form3: TForm3;

implementation

{$R *.dfm}

procedure TForm3.Button1Click(Sender: TObject);
var
  ms: TMemoryStream;
begin
  ms := TMemoryStream.Create;
  advstringgrid1.SaveToBinStream(ms);
  ms.Position := 0;
  advstringgrid2.LoadFromBinStream(ms);
  ms.Free;

end;

procedure TForm3.FormCreate(Sender: TObject);
begin
  pic := TPicture.Create;
  pic.LoadFromFile('e:\tms\temp\arrow.png');
  advstringgrid1.RandomFill(false);
  advstringgrid1.AddPicture(1,1,pic, false,noStretch,0,haLeft,vaTop);
end;

procedure TForm3.FormDestroy(Sender: TObject);
begin
  pic.Free;
end;

Dear Bruno,

Thanks it works now. I do not know why I was using function CreatePicture instead of AddPicture and use Assign() to assign image. Image was loaded and displayed in cell grid.

Wrong usage:

AdvStringGrid.CreatePicture(4, AdvStringGrid.RowCount - 1, true, NoStretch, 3, haCenter, vaAboveText).Assign( pic );

Corrected to:

AdvStringGrid.AddPicture(4, AdvStringGrid.RowCount - 1, pic , true, NoStretch, 3, haCenter, vaAboveText);

Best Regards 

Radim