Solved

Adding (and DISPLAYING!) image objects at run-time

Posted on 1997-05-01
3
168 Views
Last Modified: 2010-04-06
I am hoping that someone out there could help me with the following problem:
 
I am working on an open day project at my branch at work.  I am using an Orpheus table through Delphi to represent a forest of trees, each cell showing a little bitmap of a tree.

I need a way to show that the tree grows after some of its neighbouring trees have been removed.  I have thought of two ways:
 
  1.  Enlarging the required cells somehow.  This proved to be impossible to do, unless the whole column(s) and row(s) were enlarged.  So that method is out of the question.
  2.  Overlapping the required cells by a separate image object.  For example, cells 1A..2C.  One of the ways I used is given below:
 
******************************
procedure GrowTree(X, Y : Word); {displays a rectangle overlapping empty cells when a tree grows
}
var
  TreeImageObject : TImage;
  Corners : TRect;
  i, j : Byte;
begin
  TreeImageObject := TImage.Create(ForestForm); {create a new image to overlap the table}
{  TreeImageObject.Assign(ForestForm.Image1);}
  ImageList.Add(TreeImageObject); {Add image to a list (for future reference)}
 
  Corners := Rect(0, 0, X, Y); {set the corners to define the size of the image}
 
 
  with TreeImageObject do begin {use component features directly}
    Canvas.StretchDraw(Corners, TreeImage); {overlap grid with image using "corners" to scale it
}
    Show; {show image}
    BringToFront; {bring it in front of the other components}
  end;
end;
******************************
 
But it shows nothing.  
 
Note : I need to create several image objects at run-time whenever the "Perform Thinning" button is pressed, otherwise I could have just got around the problem by using a single object created at design time.
 
As there is nobody else here to help me with this (someone actually was but he retired a few months ago!), I had to try elsewhere.  Please help!
 
Thank you.
0
Comment
Question by:moutos
  • 2
3 Comments
 
LVL 4

Accepted Solution

by:
StevenB earned 50 total points
ID: 1335827
 If I've understood correctly then I suspect your problem may be this:
  A TImage is not a Windowed control it is a graphic control, therefore it cannot be brought in front of a control that is windowed. (Check the delphi Help on Z-Order for more info on this). What I therefore suggest is that you create a windowed control (Perhaps a TPanel) to own the Image. This windowed control can be brought in front of another windowed control to display your image.
  I'll happily elaborate on all this if you think I'm on the right track.

  Steven.
0
 

Author Comment

by:moutos
ID: 1335828
The reply proved to be quite useful, as it put me on the right track.  I did have to experiment again, though, and came up with the following solution (which actually uses default values at the momemt) which WORKS!

procedure GrowTree(X, Y : Word); {displays a rectangle overlapping empty cells when a tree grows}
var
  TreeImagePanel : TPanel;
  TreeImageObject : TImage;
  i, j : Byte;
begin
  TreeImagePanel := TPanel.Create(ForestForm); {create a new panel to overlap the table}
  ForestForm.InsertControl(TreeImagePanel); {insert new panel to the form}
  TreeImagePanel.BringToFront; {bring it to the front of all the other components/controls}
 
  TreeImageObject := TImage.Create(TreeImagePanel); {create an image object to put on the panel}
  TreeImagePanel.InsertControl(TreeImageObject); {insert image to the panel}
 
  with TreeImageObject do begin {use component features directly}
    Align := alClient; {make component cover the WHOLE client area of the panel}
    Stretch := True; {make the image inside it stretch to the new size}
    Picture.Metafile.Assign(TreeImage); {use image in TreeImage object (pre-defined and initialised elsewhere as a TMetafile object)}
  end;
 
  ImageList.Add(TreeImagePanel); {finally, add the new panel to a list (for future reference)}
end;


If you have noticed, I had to add a new statement: InsertControl.  This proved to be essential, as Delphi was still showing nothing otherwise.

Thanks very much for the suggestion!

0
 
LVL 4

Expert Comment

by:StevenB
ID: 1335829
 Glad to help. The InsertControl is required to set the parent for the objects you wish to display. I didn't pick up on that aspect of the problem, I went down the non-windowed control angle because its something that I've struggled with in the past.
  Hope your application is a success.

  Steven.
0

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Introduction The parallel port is a very commonly known port, it was widely used to connect a printer to the PC, if you look at the back of your computer, for those who don't have newer computers, there will be a port with 25 pins and a small print…
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…
A short tutorial showing how to set up an email signature in Outlook on the Web (previously known as OWA). For free email signatures designs, visit https://www.mail-signatures.com/articles/signature-templates/?sts=6651 If you want to manage em…
In an interesting question (https://www.experts-exchange.com/questions/29008360/) here at Experts Exchange, a member asked how to split a single image into multiple images. The primary usage for this is to place many photographs on a flatbed scanner…

680 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