Solved

Delphi - Load Image , File name stoed in the Database

Posted on 2011-09-23
5
1,481 Views
Last Modified: 2012-05-12
Hi Experts,
I've a Database table (MS SQL) with a field containing Path of a JPeg Image.

How can I show that in my Grid or DBCtrlGrid?

When I Try to use a Calculated field, Error saying Graphic Field can't be Calculated or Lookup field.

Any neat way to handle this?

TIA
0
Comment
Question by:pcssecure
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
5 Comments
 
LVL 19

Accepted Solution

by:
Thommy earned 500 total points
ID: 36585686
This should help you...

Drawing an image in a cell of a Delphi DBGrid´
http://delphi.about.com/library/weekly/aa032205a.htm

0
 
LVL 19

Expert Comment

by:Thommy
ID: 36585868
This is how your code should look like...
procedure TForm1.DBGrid1DrawColumnCell(Sender: TObject; const Rect: TRect;
  DataCol: Integer; Column: TColumn; State: TGridDrawState);
var
  Image1: TImage;
  ImageWidth: integer;
  fixRect: TRect;
  YourJPEGFileName:string;
begin
  if (Column.Field.FieldName = 'YourFieldName') then begin
    Image1 := TImage.Create(self);

    try

      //add code to get your jpeg filename
      YourJPEGFileName:=...

      Image1.Picture.LoadFromFile(YourJPEGFileName);

      //Adjust the image dimensions
      ImageWidth := (Rect.Bottom - Rect.Top);
      fixRect.Right := Rect.Left + ImageWidth;

      //draw image
      dbgrid1.Canvas.StretchDraw(fixRect,Image1.Picture.Graphic);

    finally
      Image1.Free;
    end;

    //add space for Image
    fixRect.Left := fixRect.Left + ImageWidth;

    //draw default text
    DBGrid1.DefaultDrawColumnCell(fixRect,DataCol,Column,State);
  end;
end;

Open in new window

0
 
LVL 19

Expert Comment

by:Thommy
ID: 36930548
Have you already tried my code????
0
 
LVL 101

Expert Comment

by:mlmcc
ID: 37144316
This question has been classified as abandoned and is closed as part of the Cleanup Program. See the recommendation for more details.
0

Featured Post

On Demand Webinar: Networking for the Cloud Era

Did you know SD-WANs can improve network connectivity? Check out this webinar to learn how an SD-WAN simplified, one-click tool can help you migrate and manage data in the cloud.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

If you haven’t already, I encourage you to read the first article (http://www.experts-exchange.com/articles/18680/An-Introduction-to-R-Programming-and-R-Studio.html) in my series to gain a basic foundation of R and R Studio.  You will also find the …
This article is meant to give a basic understanding of how to use R Sweave as a way to merge LaTeX and R code seamlessly into one presentable document.
This theoretical tutorial explains exceptions, reasons for exceptions, different categories of exception and exception hierarchy.
Viewers will learn how to properly install Eclipse with the necessary JDK, and will take a look at an introductory Java program. Download Eclipse installation zip file: Extract files from zip file: Download and install JDK 8: Open Eclipse and …

717 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question