Add Images via GetImageData

Hi,

I was looking at the example code for the Image demo project (65.Images) There the GetImageData procedure is called every time the Excel report encounters an image with a tag. The demo uses the database with the picture embedded as OleObject.
I would like to use the same approach, utilizing the GetImageData procedure, but instead of GetImageData giving me already the actual image data, I would like to get only a path / name and load that in. 

From the code, it seems it should be possible, but in my code, the procedure GetImageData, never gets called.

What is the correct approach?

Thanks,
Thomas

Note: I use TArray to pass the information to Flexcel.

 

This post was answered via email. For everyone else watching the forum, I'll paste the answer below


Hi,

I had a look at your project, and I think you are just misunderstanding GetImageData. GetImageData is designed to “process” an image (say change it to black an white) before sending it to the report. But you still need to have a valid image (in an array of bytes) in the tag where you name the image.  You name the image as <#Graph>, so Graph should be a byte array. But in your template it is a record, and this is causing the error.

To load an image on demand you would use not an array, but an user defined function. There is demo in FlexCel .NET showing just that, but sadly it was one demo I didn’t port to FlexCel for VCL due to lack of time. I’ve ported it now and it will be available in the next FlexCel VCL release.

I’ve modified your project so it runs as expected. You can get it from here:


What I’ve done:
1)Removed the “Measurements” array in TPoint. As you said in the comments, you have a relationship, so there is no need to have measuerements in point.
2)Changed the Graph array in TPoint to be just a TRImage.  I am not sure on what data model you want to implement, but it looks to me like you want a single Graph per point, so it doesn’t make sense to have an array of graphs for every point. you don’t need a separate array or Graphs either.
If you would prefer to have a separate array and not have a Graph member in TPoint, you can do it, but you will have to <#lookup(…)> into that array for every point. Here a relationship won’t help, sing you don’t have a named range with Graph

3)Added an user defined function to return the data of the image:
    Report.SetUserFunction('GraphImg', TImagesImpl.Create);


TImagesImpl is an user function that takes a parameter which is a filename, loads it and returns the byte array.

4)In the config sheet, I defined an expression:

GraphImage <#GraphImg(<#Point.Graph.FileName>)>

This will call the user defined function defined in 3) with a parameter which is Point.Graph.FileName. As I’ve added a Graph property in Point, you can get the filename here.

5)I’ve finally renamed the image to <#GraphImage> so the expression in 4) is used to fill the images.

I think this should be it. Please feel free to ask if anything isn’t clear.