?
Solved

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

Posted on 1997-05-01
3
Medium Priority
?
179 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 100 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

Enroll in August's Course of the Month

August's CompTIA IT Fundamentals course includes 19 hours of basic computer principle modules and prepares you for the certification exam. It's free for Premium Members, Team Accounts, and Qualified Experts!

Question has a verified solution.

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

In this tutorial I will show you how to use the Windows Speech API in Delphi. I will only cover basic functions such as text to speech and controlling the speed of the speech. SAPI Installation First you need to install the SAPI type library, th…
Hello everybody This Article will show you how to validate number with TEdit control, What's the TEdit control? TEdit is a standard Windows edit control on a form, it allows to user to write, read and copy/paste single line of text. Usua…
Add bar graphs to Access queries using Unicode block characters. Graphs appear on every record in the color you want. Give life to numbers. Hopes this gives you ideas on visualizing your data in new ways ~ Create a calculated field in a query: …
In this video, Percona Solution Engineer Rick Golba discuss how (and why) you implement high availability in a database environment. To discuss how Percona Consulting can help with your design and architecture needs for your database and infrastr…
Suggested Courses
Course of the Month13 days, 23 hours left to enroll

801 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