Posted by Jenny, DelphiLand Team on March 13, 2008
In Reply to Re: Selecting an item from a List Box posted by RussCAp12602 on March 12, 2008: Thanks for the reply. I am using Turbo Delphi 6, which seems to be different in many ways from the on-line help.
: It is good to know about ItemIndex, which I haven't noticed on the Properties list, and the IndexOf function.
That's because a lot of Delphi components have properties that are are objects of their own, they are like "sub-components". For example, a ListBox contains an object called Items, which is of the type TStrings. This can be seen in the Delphi Help for TListBox: as one of the properties, you see:
"Items: contains the strings that appear in the list box"
Clicking on Items shows us:
"Syntax: [Delphi] property Items: TStrings read FItems write SetItems;"
The "TStrings" is what we are interested in, it's the TYPE of Items.
Further on, this info is repeated where it says that "the items in a list box are of type TStrings".
Next, we look for TStrings in the Help, and as one of its methods we find:
"IndexOf: Returns the position of a string in the list"
Tip: when you don't find a certain property or method of a component, consider that maybe this property or method belongs to a sub-component that is a property of your original component. Search "top-down", not "bottom-up".
For example, if you're searching how to change the color of the font of TPanel, don't start looking for "fontcolor" or something similar, don't simply search for "color". Instead, go to the Help for TPanel and look at its properties; there you see: "Font: controls the attributes of text written on or in the control".
This leads you to "Syntax: [Delphi] property Font: TFont read FFont write SetFont;" -- so Panel.Font is of the type TFont. The TFont Help lists its properties, where you read "Color: specifies the color of the text".
My advise to all who are new to Delphi: regularly explore the Help system in a top-down way, so that you learn more about the "philosophy" behind it ;-)