Board index » delphi » component arrays
Johan Lindgre
![]() Delphi Developer |
Fri, 08 Mar 2002 03:00:00 GMT
|
Johan Lindgre
![]() Delphi Developer |
Fri, 08 Mar 2002 03:00:00 GMT
component arrays
I know I have seen it before but can't find it now.
Can I group a bunch of components in an array and use at run time. If I have 30-40 Timage on a page and need to reference thos like: image[x] etc johan |
Michael Winte
![]() Delphi Developer |
Fri, 08 Mar 2002 03:00:00 GMT
Re:component arraysJohan Lindgren schrieb: Quote
I guess you create them at design time. You should give them the dafault private Finally, at startup in the OnCreate method of the form, insert: for i:=1 to 40 do image[i] := HTH |
Bruce Meie
![]() Delphi Developer |
Fri, 08 Mar 2002 03:00:00 GMT
Re:component arraysHow about setting the tag property of each control to a unique value and then using (FindComponent('Image'+IntToStr(i)) as TImage) or if you want to use it in an event method: (FindComponent('Image'+IntToStr((Sender as TImage).tag) as TImage) -- > If I have 30-40 Timage on a page and need to reference thos like: > image[x] etc > johan |
Michael Winte
![]() Delphi Developer |
Fri, 08 Mar 2002 03:00:00 GMT
Re:component arraysQuoteBruce Meier wrote: set. Quote> or if you want to use it in an event method: Sender is not valid here. If this *is* used inside an event method *of one of the images*, it is much easier to say: (Sender as TImage). That's enough. -Michael |
GWhit419
![]() Delphi Developer |
Fri, 08 Mar 2002 03:00:00 GMT
Re:component arraysIn article <37E6992F.86E3E...@foni.net>, Michael Winter <win...@foni.net> writes: Quote>Bruce Meier wrote: Gordon http://members.aol.com/mgcsoft/ (the function junction equation editor) MGCSoft |
Michael Winte
![]() Delphi Developer |
Sat, 09 Mar 2002 03:00:00 GMT
Re:component arraysGWhit41980 schrieb: Quote
neccesary to set the Tag to use this statement". (I forgot that the negation of "must" has a comletely other meaning then the negation of "muessen" in German language.) -Michael |
Johan Lindgre
![]() Delphi Developer |
Sat, 09 Mar 2002 03:00:00 GMT
Re:component arraysMichael Winter skrev i meddelandet <37E71FE5.BBCC8...@aquila.de>... Quote>> >> How about setting the tag property of each control to a unique value Michaels idea worked perfectly. I have now 50 timage and 50 tlabel that I can reference through image[x] and label[x], place and fill with the info when the page is updated. I am using the tag property to keep track of the id of the picture displayed. So if I display a certain picture in an image and the user double clicks on that image I can through the tag property find out the id of the actual picture. Regardless of which position that image has in the image-array. johan |
GWhit419
![]() Delphi Developer |
Sat, 09 Mar 2002 03:00:00 GMT
Re:component arraysQuoteIn article <37E71FE5.BBCC8...@aquila.de>, Michael Winter <m...@aquila.de> writes: quarter as good as your English I'd probably have known that :) Gordon http://members.aol.com/mgcsoft/ (the function junction equation editor) MGCSoft |
AlanGLLo
![]() Delphi Developer |
Sat, 09 Mar 2002 03:00:00 GMT
Re:component arraysIn article <19990920191934.07848.00000...@ngol03.aol.com>, gwhit41...@aol.com Quote(GWhit41980) writes: <g> but setting Tags is in general _not_ a good Idea because it makes the code opaque. It is the same as using "magic numbers". It makes you refer to other (or hidden) areas of your application code before you can understand what the particular element of code is doing. If you absolutely _have_ to do it then either put a chunk of comments by the My strictures, of course, are not valid if you are writing some form of Alan Lloyd |
GWhit419
![]() Delphi Developer |
Sun, 10 Mar 2002 03:00:00 GMT
Re:component arraysIn article <19990921160856.07765.00000...@ngol06.aol.com>, alangll...@aol.com Quote(AlanGLLoyd) writes: Quote
this instance I can't think of an easier way than for var:= 0 to high(Images) do Very easy and IMO very readable. [snip] Gordon. ~~~~~~~~~~~~~~~~~~~~~~~~ http://members.aol.com/mgcsoft/ (the function junction equation editor) MGCSoft |
Johan Lindgre
![]() Delphi Developer |
Sun, 10 Mar 2002 03:00:00 GMT
Re:component arraysGWhit41980 skrev i meddelandet >I doubt whether there are any instances Quote>this instance I can't think of an easier way than maybe I was doing something else wrong. If you use this approach, do you need to free the images also? johan |
Bj?rge S?the
![]() Delphi Developer |
Sun, 10 Mar 2002 03:00:00 GMT
Re:component arraysYou'll have to Set Image's Parent property (and Visible, too, if they don't show up). var ...and yes, you'll have to free them... -- Bjoerge Johan Lindgren skrev i meldingen Quote
|
AlanGLLo
![]() Delphi Developer |
Sun, 10 Mar 2002 03:00:00 GMT
Re:component arraysIn article <19990922023737.08086.00000...@ngol02.aol.com>, gwhit41...@aol.com Quote(GWhit41980) writes: would count this as a "meta-handler" where the particular identifier does not matter - you are just handling them all, and the particular image is readily identifiable in the code as Images[var]. And in answer to Johann's query, Images must be displayed on a Canvas, which is Images[var].Canvas := "some WinControl".Canvas There are many WinControls which do have a canvas. And yes you do need to free the images. Alan Lloyd |
Bruce Robert
![]() Delphi Developer |
Sun, 10 Mar 2002 03:00:00 GMT
Re:component arraysQuote> ..... Quote
|
GWhit419
![]() Delphi Developer |
Sun, 10 Mar 2002 03:00:00 GMT
Re:component arraysIn article <19990922144112.11196.00000...@ngol03.aol.com>, alangll...@aol.com Quote(AlanGLLoyd) writes: Gordon. http://members.aol.com/mgcsoft/ (the function junction equation editor) MGCSoft |