Solved

Delphi - Load Image , File name stoed in the Database

Posted on 2011-09-23
5
1,372 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
Comment Utility
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
Comment Utility
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
Comment Utility
Have you already tried my code????
0
 
LVL 100

Expert Comment

by:mlmcc
Comment Utility
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

How to improve team productivity

Quip adds documents, spreadsheets, and tasklists to your Slack experience
- Elevate ideas to Quip docs
- Share Quip docs in Slack
- Get notified of changes to your docs
- Available on iOS/Android/Desktop/Web
- Online/Offline

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
matchUp  challenge 6 48
Create Database on Android via Delphi dbExpress 3 66
firstChar challenge 13 83
Copy Files - Python 7 53
Creating an auto free TStringList The TStringList is a basic and frequently used object in Delphi. On many occasions, you may want to create a temporary list, process some items in the list and be done with the list. In such cases, you have to…
How to remove superseded packages in windows w60 or w61 installation media (.wim) or online system to prevent unnecessary space. w60 means Windows Vista or Windows Server 2008. w61 means Windows 7 or Windows Server 2008 R2. There are various …
This tutorial explains how to use the VisualVM tool for the Java platform application. This video goes into detail on the Threads, Sampler, and Profiler tabs.
The goal of the video will be to teach the user the concept of local variables and scope. An example of a locally defined variable will be given as well as an explanation of what scope is in C++. The local variable and concept of scope will be relat…

771 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

Need Help in Real-Time?

Connect with top rated Experts

15 Experts available now in Live!

Get 1:1 Help Now