Solved

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

Posted on 1997-05-01
3
172 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
[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
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

Have you ever had your Delphi form/application just hanging while waiting for data to load? This is the article to read if you want to learn some things about adding threads for data loading in the background. First, I'll setup a general applica…
In my programming career I have only very rarely run into situations where operator overloading would be of any use in my work.  Normally those situations involved math with either overly large numbers (hundreds of thousands of digits or accuracy re…
How to Install VMware Tools in Red Hat Enterprise Linux 6.4 (RHEL 6.4) Step-by-Step Tutorial

734 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