?
Solved

Showing and selecting images in a TDrawGrid

Posted on 2004-05-02
4
Medium Priority
?
1,493 Views
Last Modified: 2012-08-14
1. I would like to show a list of images in a drawgrid
2. I want to be able to select an image from the grid
3. I would also like to be able to select 2 images from the grid

I am starting with a list of filenames held in s string list, all the files are small JPEG files. Could someone please give me some standard code to show these images in a DrawGrid as there seems to be no useful doumentation. After I have the images showing I would like to be able to click on a cell in the drawgrid and show the picture in a TImage component or click on two cells and show the images in two TImage components.

Thanks in advance - Dan
0
Comment
Question by:seabear
[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
  • 2
4 Comments
 
LVL 6

Expert Comment

by:Amir Azhdari
ID: 10975022
0
 
LVL 6

Expert Comment

by:Amir Azhdari
ID: 10975086
0
 
LVL 12

Accepted Solution

by:
Ivanov_G earned 1000 total points
ID: 10976208
unit Unit1;

interface

uses
  Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs, jpeg,
  StdCtrls, ExtCtrls, Grids;

type
  TForm1 = class(TForm)
    DrawGrid1: TDrawGrid;
    Image1: TImage;
    Button1: TButton;
    procedure Button1Click(Sender: TObject);
    procedure DrawGrid1DrawCell(Sender: TObject; ACol, ARow: Integer;
      Rect: TRect; State: TGridDrawState);
    procedure DrawGrid1SelectCell(Sender: TObject; ACol, ARow: Integer;
      var CanSelect: Boolean);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  Form1: TForm1;

implementation

{$R *.DFM}

procedure TForm1.Button1Click(Sender: TObject);
var jpg : TJPEGImage;
    bmp : TBitmap;
    rect : TRect;
begin
  // load the JPG
  jpg := TJPEGImage.Create;
  jpg.LoadFromFile('D:\Work\grepsearch.JPG');
  // assign in Bitmap
  bmp := TBItmap.Create;
  bmp.Assign(jpg);
  // draw in the DrawGrid;
  rect := DrawGrid1.CellRect(0, 0);
  DrawGrid1.Canvas.StretchDraw(rect, bmp);
end;

procedure TForm1.DrawGrid1DrawCell(Sender: TObject; ACol, ARow: Integer;
  Rect: TRect; State: TGridDrawState);
var jpg : TJPEGImage;
    bmp : TBitmap;
    rectt : TRect;
begin
  // load the JPG
  jpg := TJPEGImage.Create;
  jpg.LoadFromFile('D:\Work\grepsearch.JPG');
  // assign in Bitmap
  bmp := TBItmap.Create;
  bmp.Assign(jpg);
  // draw in the DrawGrid;
  rectt := DrawGrid1.CellRect(0, 0);
  DrawGrid1.Canvas.StretchDraw(rectt, bmp);
end;

procedure TForm1.DrawGrid1SelectCell(Sender: TObject; ACol, ARow: Integer;
  var CanSelect: Boolean);
var
  rect : TRect;
begin
  rect := DrawGrid1.CellRect(ACol, ARow);
  Image1.Canvas.CopyRect(rect, DrawGrid1.Canvas, rect);
end;

end.
0
 

Author Comment

by:seabear
ID: 10999922
Thank you Azhdari and Victor,
       The code that best fits what I want is Victor's so I have accepted his answer. Thank you both for your time - Dan
0

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

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

A lot of questions regard threads in Delphi.   One of the more specific questions is how to show progress of the thread.   Updating a progressbar from inside a thread is a mistake. A solution to this would be to send a synchronized message to the…
Introduction I have seen many questions in this Delphi topic area where queries in threads are needed or suggested. I know bumped into a similar need. This article will address some of the concepts when dealing with a multithreaded delphi database…
This tutorial will teach you the special effect of super speed similar to the fictional character Wally West aka "The Flash" After Shake : http://www.videocopilot.net/presets/after_shake/ All lightning effects with instructions : http://www.mediaf…
How to fix incompatible JVM issue while installing Eclipse While installing Eclipse in windows, got one error like above and unable to proceed with the installation. This video describes how to successfully install Eclipse. How to solve incompa…
Suggested Courses
Course of the Month10 days, 19 hours left to enroll

770 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