Solved

Delphi - Load Image , File name stoed in the Database

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

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
groupSumClump challenge 9 117
wordcount challenge 11 124
Change to event 1 115
how can i search if string exist in array ? 3 59
In this tutorial I will show you how to use the Windows Speech API in Delphi. I will only cover basic functions such as text to speech and controlling the speed of the speech. SAPI Installation First you need to install the SAPI type library, th…
There is an easy way, in .NET, to centralize the treatment of all unexpected errors. First of all, instead of launching the application directly in a Form, you need first to write a Sub called Main, in a module. Then, set the Startup Object to th…
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 …
The viewer will learn how to pass data into a function in C++. This is one step further in using functions. Instead of only printing text onto the console, the function will be able to perform calculations with argumentents given by the user.

825 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