Question

Indexing a Timage component in delphi 5

Asked by: tandy

Hi,

I am trying to find a way to create a set of
timage controls that can be referenced by
index. I have done some programming In VB
where it is a simple menu choice to set an index. There does not seem to be any way to do this in delphi 5.0.  Is there a way to rerference a particuliar timage component by
index?

This Question has been solved and asker verified All Experts Exchange premium technology solutions are available to subscription members.

Subscribe now for full access to Experts Exchange and get

Instant Access to this Solution

  • Plus...
  • 30 Day FREE access, no risk, no obligation
  • Collaborate with the world's top tech experts
  • Unlimited access to our exclusive solution database
  • Never be left without tech help again

Subscribe Now

Asked On
2004-06-10 at 10:08:43ID21021206
Tags

delphi

,

timage

Topic

Delphi Programming

Participating Experts
4
Points
500
Comments
12

Trusted by hundreds of thousands everyday for fast, accurate and reliable tech support.

  • "The time we save is the biggest benefit of Experts Exchange to Warner Bros. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange." Mike Kapnisakis, Warner Bros.
  • "Our team likes having a resource that is more secure than just using Google and most experts using this service really know their stuff. It's nice to look here first versus using Google." Dayna Sellner, Lockheed Martin
  • "Anytime that I've been stumped with a problem, 9 out of 10 times Experts Exchange has either the accepted solution or an open discussion of the potential solution to the problem." Kenny Red, eBay Inc.

See what Experts Exchange can do for you.

Got a question?

We've got the answer.

Experts Exchange has been collecting answers to technology questions since 1996…3 million and counting! If you have a question, chances are we already have your answer.

Screenshot of Experts Exchange Knowledgebase

Need individual assistance?

Our experts are ready to help.

If you can't find the exact answer you're looking for, ask our exclusive community of 50,000 experts. You’ll get a personalized answer from a trusted professional.

Screenshot of Experts Exchange Knowledgebase

Want to learn from the best?

Read articles from industry experts.

Thousands of free tech tips, tricks, how-to’s and tutorials are available in our peer reviewed articles section. See for yourself how smart our experts are, no login required.

Screenshot of an Article

Working on a long term project?

Store your work and research.

Save solutions to your questions, answers you’ve discovered through searching plus helpful articles in your personal knowledgebase for easy future access.

Screenshot of Experts Exchange Knowledgebase

Access the answers to your technology questions today.

Subscribe Now

30-day free trial. Register in 60 seconds.

What Makes Experts Exchange Unique?

Members of the expert community talk about why the experience at Experts Exchange is different than what you will find anywhere else.

Trusted by the world's most respected brands.

image of each brand's logo

Faithfully serving IT professionals since 1996.

Experts Exchange Logo

Try it out and discover for yourself.

Subscribe Now

30-day free trial. Register in 60 seconds.

Related Solutions

  1. TImage form ImageList
    Who can i show an image from an imagelist ? is there a component for it ? I don't want to load it manually, because i change the icon in the ImageList and want that it is automatically updated in every TreeView, ListView, ... and in my TImage !
  2. Antialiased TImage?
    Is there anyway to remove the jagged edges of an line drawn on the canvas of a TImage in realtime?
  3. Changing Images(TImage)
    Hello, I have a TImage component and two buttons on a form(captioned previous pic/next pic) and various bitmaps scattered in various folders!I can load an initial image by double clicking on the TImage component but how do I change that image when I use the buttons(bearing in...
  4. TImage
    My app uses a 800x600 TImage as a background. It's loaded at design time so I assume the data is in my res file. When the form is shown the first time, the controls in the foreground appear before the Image in the background (loading time?) How can I paint the image to the...
  5. TImage Properties...
    Hi, Does anyone know how I can determine the type of file and the file path that has been loaded into a TImage component? Thanks Paul
  6. TImage ...
    I Want to add a TImage on my form so it can show a .bmp/.jpg file and can convert and save it to .jpg format.

Free Tech Articles

  1. WARNING: 5 Reasons why you should NEVER fix a computer for free.
    It is in our nature to love the puzzle. We are obsessed. The lot of us. We love puzzles. We love the challenge. We thrive on finding the answer. We hate disarray. It bothers us deep in our soul. W...
  2. SCCM OSD Basic troubleshooting
    SCCM 2007 OSD is a fantastic way to deploy operating systems, however, like most things SCCM issues can sometimes be difficult to resolve due to the sheer volume of logs to sift through and the dispe...
  3. Migrate Small Business Server 2003 to Exchange 2010 and Windows 2008 R2
    This guide is intended to provide step by step instructions on how to migrate from Small Business Server 2003 to Windows 2008 R2 with Exchange 2010. For this migration to work you will need the fo...
  4. Create a Win7 Gadget
    This article shows you how to create a simple "Gadget" -- a sort of mini-application supported by Windows 7 and Vista. Gadgets can be dropped anywhere on the desktop to provide instant information, ...
  5. Outlook continually prompting for username and password
    There have been a lot of questions recently regarding Outlook prompting for a username and password whilst using Exchange 2007. There are a few reasons why this would happen and I will try to cover t...
  6. Backup Exchange 2010 Information Store using Windows Backup
    There seems to be quite a lot of confusion around the ability to backup Exchange 2010 using the built in Windows Backup feature. This stems from the omission of this feature prior to Exchange 2007 s...

Cloud Class Webinars

  1. Avoiding Bugs in Microsoft Access
    Alison Balter takes and in-depth look at avoiding bugs in Access. In this webinar you will learn about using the immediate window to debug your applications, invoking the debugger, using breakpoints to troubleshoot, stepping through code, setting the next statement to execute, ...
  2. Top 10 Best New Features in Visio 2010
    Scott Helmers gives live demonstrations of the top 10 new features in Visio 2010. This webinar will teach you how to create compelling diagrams by adding shapes to the page with a single click, linking the shapes in a diagram to data in Excel (or SQL Server, or SharePoint), ...
  3. IT Consultant Business Secrets Revealed
    Michael Munger, Experts Exchange tech pro and IT consultant, pulls back the curtain on his very successful businesses and answers question on every IT consultant and business owner should know about. He shares secrets on what he did to solve the 5 most common problems in IT, ...
  4. Disaster Recovery and Business Continuity
    Quest CTO, Mike Billon, gives an overview of the steps involved in building a dunamic disaster recovery plan. Through case studies and an examination of software/hardware tooles for monitoring and testing, you'll gain a better understandin of where you are, where you want ...
  5. Organize Your Visio Diagrams with Containers and Lists
    Scott Helmers uses cross functional flowcharts, wireframe diagrams, data graphic legends and seating charts to teach you: how to ustilize all three new structured diagram components in Visio 2010, the best practices for organizeing shapes in previous version of Visio, how to organize ...
  6. How to Us Objects, Properties, Events and Methods in Microsoft Access
    Alison Dalter gives an in-depbth look at objects, properties, events and methods in Microsoft Access. In this webinar you will learn about using the object browser, referring to objects, working with properties and methods, working with object variables, understanding the ...

Join the Community

Give a Little. Get a Lot.

Join the community of experts here and help other tech pros by answering question in your area of expertise. You can earn FREE access to all Experts Exchange's premium features and resources.

Join the Community

Answers

 

by: ExtasePosted on 2004-06-10 at 10:15:18ID: 11281650

try to use an ImageList component(TImageList) instead.

 

by: Paul_UKPosted on 2004-06-10 at 10:57:53ID: 11282100

Hi,

You could set the Tag property of the TImage component, and then add the following function the form:

function TForm1.FindImageByIndex(Index: Integer): TImage;
var
  I: Integer;
begin
  Result := NIL;
  i := 0;
  while (Result = NIL) and (I < ComponentCount) do
  begin
    if (Components[I] is TImage) and (Components[I].Tag = Index) then
      Result := TImage(Components[I]);
    inc(i);
  end;
end;


Then you can call this function, passing the required index number (which matches the Tag property), and it will return the matching TImage component.

Cheers,
Paul

 

by: mokulePosted on 2004-06-10 at 12:19:23ID: 11282957

You can also do as follows

var
  c : TComponent;
begin
 c := FindComponent('Image1');
 if Assigned(c) then
   if c is TImage then
     (c as TImage).Left := 1;  // do whatever want

 

by: ExtasePosted on 2004-06-10 at 12:26:14ID: 11283018

type
  TForm1 = class(TForm)
    procedure FormCreate(Sender: TObject);
    procedure FormDestroy(Sender: TObject);
  private
    FImages:TList;
  public
    function AddImage:TImage;
    procedure RemoveImage(const Index:Integer);
    function GetImage(const Index:Integer):TImage;
  end;

var
  Form1: TForm1;

implementation

{$R *.dfm}

function TForm1.AddImage:TImage;
begin
  Result:=TImage.Create(Self);
  Result.Parent:=Self;
  FImages.Add(Result);
end;

procedure TForm1.RemoveImage(const Index:Integer);
begin
  GetImage(Index).Free;
  FImages.Delete(Index);
end;

function TForm1.GetImage(const Index:Integer):TImage;
begin
  Result:=FImages[Index];
end;

procedure TForm1.FormCreate(Sender: TObject);
begin
  FImages:=TList.Create;
end;

procedure TForm1.FormDestroy(Sender: TObject);
begin
  FImages.Free;
end;

 

by: tandyPosted on 2004-06-10 at 21:29:43ID: 11285842

>>Extase:
>>try to use an ImageList component
>>(TImageList) instead.

I have a ImageList component to store  and access the images(bitmaps) I am using.

I still need to be able to draw the image to a certain place on my form which I have
designated as a series of timage components.

In VB I would use an array of
images each accesible by an image Index.

By your responses it seems there is no 'internal' property to do this and one must resort to code to find the appropriate
component.

>>Paul_UK  
Nice code, I  ran it and it works.() Seems like a lot of processing though seeing as I have 100 images to cycle through each time I want to access one image..
Pehaps this is the only way it can be done.

Also, I would have to manually set the tag properties of all the components.
This is the solution I will use if none
better arises...


>>mokule

Your procedure looks like it would work fine but the  the logic processing will envlove integer representaions of the
picture elements and converting back and forth using text arguements would be cumbersome :) That is the program will
select ,say the number 4 and I would want to access the element using the integer value...
 

I will leave the question open to see if there
are any more responses...thanks all for your help, (Us VB programmers really need it :)..

 

by: kretzschmarPosted on 2004-06-10 at 22:25:16ID: 11286067

>I have a ImageList component to store  and access the images(bitmaps)
>I am using.

>I still need to be able to draw the image to a certain place on my form
>which I have
>designated as a series of timage components.

as you have a imagelist in use, then you have also an index
-> the imagelist can accessed like an array

to paint it on your form you've multiple possibilties
- using windows-api (bitBlt for ex)
- using vcl (canvas Stretchdraw for ex)

use the forms onPaint-event to keep your formpainting/display consistent

what is your problem?

meikl ;-)

 

by: Paul_UKPosted on 2004-06-11 at 00:28:43ID: 11286543

Or, if you don't need to stretch the images, you could just use the Draw method of the ImageList, e.g.

  ImageList1.Draw(Canvas, Left, Top, ImageIndex);

Where ImageIndex is the index number of the required image in the ImageList.

Cheers,
Paul

 

by: tandyPosted on 2004-06-11 at 07:12:22ID: 11288790

>kretzschmar

>use the forms onPaint-event to keep your >formpainting/display consistent

>what is your problem ?

Thanks for the response kreztschmar. My problem perhaps
is two fold. Being new to delphi programming its difficult not to think in terms of VB. I was looking for a way
to access the Timage element because the properties and methods of that component really suit well the model I
am trying to construct.

I do realize the TImageList is an array and the elements
contained can be accessed as such. I also realize that contents of the list can be wriiten to the form (or to any element for that matter). However, not only would it be more tedious to draw all the elements using x and y co-ordinates,the images would also lack the event handling methods that I utilize as the user clicks on an image.

I can use the TImageList control to select the particuliar picture that will be drawn onto the Timage . However, I still have to find the location to draw to , which, using my model
would be an integer value repesenting the component.

Thanks again for your input. I am sure there would be many
other ways to accomplish the same task, however I find it easier to manipulate the code using the timage object. I will use Paul_UK ' s  solution . I do think though that the image control index of VB is a superior system for this type of project and I am surprised that the delphi VCL does not support it. (Spoken like a true VB programmer eh :).

Thanks again,
Tandy
 

 

by: kretzschmarPosted on 2004-06-11 at 07:32:41ID: 11288985

>(Spoken like a true VB programmer eh :).

no not really,
but delphi didn't support control-arrays at designtime,
but you can do it at runtime of course

for ex

  imageArr : Array[0..11] of TImage; //12 images just for example

now you could drop 12 TImage-components on the form
and do you desired layout and assign the events you need

to transport the 12 TImages into the array,
just write a onFormCreate-event handler,
where you transfer the references into the array like

imageArr[0] := Image1;
imageArr[1] := Image2;
imageArr[2] := Image3;
imageArr[3] := Image4;
imageArr[4] := Image5;
imageArr[5] := Image6;
imageArr[6] := Image7;
imageArr[7] := Image8;
imageArr[8] := Image9;
imageArr[9] := Image10;
imageArr[10] := Image11;
imageArr[11] := Image12;

i personally would prefer a tlist (IList : TList)    rather than an array,
like extase suggested, in this the tranfer in the formcreate-event would be

IList := TList.Create;
Ilist.Add(Image1);
Ilist.Add(Image1);
Ilist.Add(Image2);
Ilist.Add(Image3);
Ilist.Add(Image4);
Ilist.Add(Image5);
Ilist.Add(Image6);
Ilist.Add(Image7);
Ilist.Add(Image8);
Ilist.Add(Image9);
Ilist.Add(Image10);
Ilist.Add(Image11);
Ilist.Add(Image12);
 
a tlist has some benefits
- is dynamic
- has some good methods

if you now assign a general onClick-event to all TImages for ex,
and you want to know which image is now clicked, then its became easy

procedure GeneralImageClick(sender : TObject);
var
  i : Integer;  
begin
  i := IList.IndexOf(sender);
  if i > - 1 then  //is the sender a TImage from the list
    TImage(IList[i]).Visible := false;  //just as sample
end;

well,
anyway glad that paul helped you,
have a nice time with delphi,
hoping you will like delphi in future as you like vb now

good luck again

meikl ;-)


 


 

by: tandyPosted on 2004-06-11 at 18:52:20ID: 11293944

Thanks for the extra comments after
the answer was accepted kretzschmar.

Your code looks very sophistcated and will add value to
this question as a PAQ. I will have a look at it again when I
get more comfortable with the basics of Delphi. I really do
like Delphi but for many of the small projects I work on, the
methods such as you describe are really beyond the scope of
what I need to produce. The biggest reason I switched to Delphi was because my VB(4.0) is outdated and it seems to have so many dependencies on support files. Delphi(5.0) seems to generate smaller code and is more portable.
 
 Thanks to all,
Happy Coding :)
Tandy

 

by: ExtasePosted on 2004-06-12 at 00:54:58ID: 11294844

example using a TImageList component.

type
  TForm1 = class(TForm)
    ImageList1: TImageList;
    Image1: TImage;
    Button1: TButton;
    Edit1: TEdit;
    Button2: TButton;
  private
  public
    procedure DrawImage(const Index:Integer);
  end;

implementation

{$R *.dfm}

procedure TForm1.DrawImage(const Index:Integer);
begin
  with Image1.Picture do
  begin
    with Bitmap do
    begin
      Height:=0;
      Width:=0;
    end;
    ImageList1.GetBitmap(Index, Bitmap);
  end;
end;

 

by: ExtasePosted on 2004-06-12 at 00:59:36ID: 11294852

// no real need for button1, button2 & edit1 :D

20120131-EE-VQP-002

3 Ways to Join

30-Day Free Trial

The Experts

98% positive feedback on 31,087 answers since March 2000. angeliii is a Microsoft Most Valuable Professional for his work with MS SQL Server & Develoment.

He has also proven his knowledge of Visual Basic Programming, PHP Scripting and Oracle Databases.

The Experts

97% positive feedback on 10,752 answers since July 2000. lrmoore has more than 18 years experience in the networking industry.

The six-time Mircosoft MVPs specialties include firewalls, virtual private networking, and network management.

Testimonials

"...and excellent source for support... Kind of like having your very own IT dept." Electriciansnet

Testimonials

"I was apprehensive at signing up at first. However... it has already made my life as an IT administrator much easier." JaCrews

Testimonials

"WOW! You guys have great, active, and knowledgeable people on here." moore50

Business Clients

Business Clients

In the Press

"If you’ve got a question... Experts Exchange can supply an answer.”

In the Press

"...an invaluable aid for both IT professionals and those who require tech support."

In the Press

"where IT professionals provide quick answers on just about any topic"

Business Account Plans

Loading Advertisement...