Solved

Delphi - Load Image , File name stoed in the Database

Posted on 2011-09-23
5
1,466 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 100

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

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
CheckListBox usage 3 97
Android development question 2 108
How to Get Images From Server to Client using App Tethering 1 56
Microsoft Access 97 and Delphi XE2 9 85
This article will show, step by step, how to integrate R code into a R Sweave document
When we want to run, execute or repeat a statement multiple times, a loop is necessary. This article covers the two types of loops in Python: the while loop and the for loop.
The goal of the tutorial is to teach the user how to use functions in C++. The video will cover how to define functions, how to call functions and how to create functions prototypes. Microsoft Visual C++ 2010 Express will be used as a text editor an…
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 …

732 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