In article <6rgdlg$...@tandem.CAM.ORG>, "Raymond Bissonnette" <rayb...@cam.org>
writes:
Quote
>In VB I could easily use a control array to reference the sender label
>directly (using it's index property) but I have no clue on how to do this
>in Dephi. I just got Delphi 4 Standard and I like the tool very much but
>have more difficulties with the doc.
>I would be happy just being able to use something like "Sender.Name" or a
>common handler set at design time like:
The best way is just to typecast the Sender object to access the particular
"Sender"
Sender is specified as a TObject so you cannot say Sender.Font.Color because a
TObject does not have a Font (let alone a colour) and the compiler says that
you cannot do that. But you can "typecast" the TObject to your particular
object which does have a Font. But the compiler is taking your word and if you
are wrong its a run-time error. So you code :-
TLabel(Sender).Font.Color := clYellow;
There are two arrays of objects - Components[] (items whose Owner is the object
with the array), and Controls[] (items whose Parent is the object with the
array). Most items on a form are Owned by the form. But items visually placed
on an object are children of that particular object (ie a TButton on a Form is
owned and parented by the form, a TButton placed on a TPanel is owned by the
Form, but Parented by the TPanel).
Having these arrays you can look for identity with some known value. Rather
like the above but look through the array of components to establish a match
with numbers you have specified. Suppose you put a value of 24 in the Tag
property of an TLabel, you could find the particular TLabel by coding :-
for i := 0 to ComponentCount - 1 do
if Components[i].Tag := 24 then // this is your component
etc etc
. . or look for the name . . .
for i := 0 to ComponentCount - 1 do
if Components[i].Name := 'MyLabel1' then // this is your component
etc etc
. . . but note that Components[i] is a TComponent and so you cannot access a
property (like Tag or Name) unless a TComponent has that property or you
typecast the Components[i] to your component descendant which has the property
you're using (ie TLabel(Components[i]).Font.Color := clYellow).
Similarly for the Controls[] array.
Note also that Delphi will use the Form instance (Self) by default to make a
fully qualified name. So if you code Controls[i], Delphi takes it as
"YourFormInstance".Controls[i]. If you want to look at the controls on a TPanel
you would have to specify MyPanel.Controls[i].
Alan Lloyd
alangll...@aol.com