• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 218
  • Last Modified:

Dynamic Instance of Image

How can I create a Dynamic Instance of TImage?
in TImage constructor it is asking for TComponents as a parameter. but which TComponents i should pass? it shows runtime error. please help me asap......
0
Mukesh_21
Asked:
Mukesh_21
  • 3
  • 2
  • 2
  • +1
1 Solution
 
kretzschmarCommented:
usualy you have a form,
where you create it, so you can do as follows

var t:TImage;
begin
  with TImage.Create(Self) do //self is your form-instance
  begin
    parent := self; //if it should shown on the form, but it could also be a tpanel (panel1 for ex.)
    top := whatever;
    //other properties
  end;
end;

meikl ;-)
0
 
kretzschmarCommented:
oops
forget the line

var t:TImage;

0
 
MotazCommented:
var
  Image: TImage;
begin
  Image:= TImage.Create(self); // Self = current form
  Image.parent:= Self; // The area in which Image will be displayed
  Image.Picture.LoadFromFile...
end;

Motaz
0
Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

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.

 
Lukasz LachCommented:
var img: TImage;
begin
  img := TImage.Create(self);
  img.Parent := Form1;
  ...
end;
0
 
Lukasz LachCommented:
lol, so quickly... ;-)
0
 
MotazCommented:
Create(Owner):
Owner is the container component that hold refrences to thier component, if you free that owner (For example a form or a panel) all it's components will be freed, so that don't attempt to free your image manually at run-time. If you want to do that then assign nil to owner:

Image:= TImage.Create(Nil);

Parent property is very important, because it is the area in which your component will be displayed, for example, Form, Panel, or GroupBox, if you hide this parent, then your image will be hidden, or if you disable it, your image will be disabled.

You can assign different Owner and Parent for one created Component

Motaz
0
 
Mukesh_21Author Commented:
Thanks a lot...
0
 
kretzschmarCommented:
hmm . . .
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.

  • 3
  • 2
  • 2
  • +1
Tackle projects and never again get stuck behind a technical roadblock.
Join Now