Solved

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

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

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

The uses clause is one of those things that just tends to grow and grow. Most of the time this is in the main form, as it's from this form that all others are called. If you have a big application (including many forms), the uses clause in the in…
Objective: - This article will help user in how to convert their numeric value become words. How to use 1. You can copy this code in your Unit as function 2. than you can perform your function by type this code The Code   (CODE) The Im…
This video discusses moving either the default database or any database to a new volume.
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

746 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

9 Experts available now in Live!

Get 1:1 Help Now