[Last Call] Learn about multicloud storage options and how to improve your company's cloud strategy. Register Now

x
?
Solved

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

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

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say 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

This article explains how to create forms/units independent of other forms/units object names in a delphi project. Have you ever created a form for user input in a Delphi project and then had the need to have that same form in a other Delphi proj…
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…
Visualize your data even better in Access queries. Given a date and a value, this lesson shows how to compare that value with the previous value, calculate the difference, and display a circle if the value is the same, an up triangle if it increased…
Sometimes it takes a new vantage point, apart from our everyday security practices, to truly see our Active Directory (AD) vulnerabilities. We get used to implementing the same techniques and checking the same areas for a breach. This pattern can re…
Suggested Courses

650 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