saving pictures in a stringgrid

I am using a TadvStringGrid as a storage device.  I add information and
manipulate the data in the grid and then use the built in
Grid.SaveToBinFile() and Grid.LoadFromBinFile() to save and open the
files for use.



I am adding images to the grid using

Grid.CreatePicture(c,r,transparency,nostretch,padding,halign,valign).LoadFromFile();


and displaying the pictures using a TImage component.

Image1.Picture:=Grid.GetPicture(c,r);

This all works fine.



Where I am having trouble is figuring out how I can actually save the
picture in the grid so that when it is opened I can view the images
without having to reload the original images again.



I am combining several grids into 1 for saving so cell information is
transfered from the individual grids into a single grid for saving using
something like:

savegrid.cells[c,r]:=grid1.cells[c,r]; (works fine for any text etc.)

to move the picture cells I use

savegrid.AddPicture(c,r,Grid1.GetPicture(c,r),false,nostretch,1,Halign,Valign);

I can see the images in the grid but it does not look like I can save
the pictures this way.

What am I missing?



Thanks for any help.



KS

Sorry, put in wrong section.  Belongs in VCL
didn't see any edit or delete capabilities.

Moderator please move this to the proper location.

Thanks

[Topic moved to VCL Components > Grids]

I cannot see any problem with this.

Tested with two grids on the form and the code:

begin
  advstringgrid1.CreatePicture(1,1,false,TStretchMode.noStretch, 2, haLeft, vaTop).LoadFromFile('C:\tmssoftware\Graphics\Components\advgrid.bmp');
  advstringgrid1.SaveToBinFile('grid.bin');
  advstringgrid2.LoadFromBinFile('grid.bin');
end;

and this loads data from grid1, included the image in cell 1,1 in grid2

Hi Bruno,
The error appears to be when I try to copy the jpg image from one grid to the other before saving.  If there is no image in grid1 then an error occurs when the grid checks the image size of the image that should be in grid2.  I didn't notice this as it only shows if you actually view the grid.
What can I do to check the first gird's cells to see if an image exists before I use savegrid.AddPicture(c,r,Grid1.GetPicture(c,r),false,nostretch,1,Halign,Valign);

to copy the image over?

Is there a check I can use to verify the Tpicture exists in the first grid?
I tried using Grid1.GetPicture(c,r).bitmap.empty but that does not work.

Thanks for your help.
KS

update

I ensured the error didn't exist by loading stock images in all the cells.
However, even though the images appear in the save grid, they do not save with the grid.

The save and Open works if I load the images directly into the save grid but it doesn't work when I transfer the images from the first grid to the save grid.  I must be using the wrong method to transfer the information into the save grid.

What is the proper way to transfer the image from one grid to another?

Thanks for  any help.
KS

what method of "transfer" do you use?

You should always use CreatePicture() and assign then from one picture to the created picture

Thanks Bruno,

That was my problem.  I was using AddPicture().  using CreatePicture and assigning the picture from the other grid solved the problem for me.

Thanks again.

Kim