View previous topic :: View next topic |
Author |
Message |
sepa
Joined: 06 May 2007 Posts: 13
|
Posted: Sun Dec 09, 2007 6:04 am Post subject: How it's planned to get AutoComplete list number? |
|
|
I'm interesting how to get number of curent selected line in ACP onChange event. I see in AutoComplete demo of v2.40 such code:
Code: |
with AutoCompletePopup1.ListBox do
if ItemIndex = -1 then Idx := -1
else Idx := integer(Items.Objects[ItemIndex]);
if Idx <> -1 then
AutoCompletePopup1.ToolHint.Text := AutoCompletePopup1.Items[Idx]
else
AutoCompletePopup1.ToolHint.Text := ''; |
But it doesn't work, integer(object) allways = 0. Because you have TList.text:=TList.text in renderer without passing objects.
So question is: is it planned to get listbox.objects property work? or this was only draft and nothing will be changed?
Now i have to:
Code: |
if AutoCompletePopup1.ListBox.ItemIndex <> -1 then
s := AutoCompletePopup1.GetListItem(AutoCompletePopup1.ListBox.ItemIndex);
i:=AutoCompletePopup1.Items.IndexOf(s);
|
but there will be more better if it was in onChange parameters, something like
Code: |
procedure TfmMain.AutoCompletePopup1Change(Sender: TObject; const num: integer);
|
=) |
|
Back to top |
|
|
econtrol Site Admin
Joined: 09 Jun 2006 Posts: 202
|
Posted: Sun Dec 30, 2007 9:09 am Post subject: |
|
|
Yes, ListBox.Items.Objects[] does not contain anything and even ListBox.Items does not contain any items. In last version (2.40) virtual items are used, i.e. without filling ListBox.Items at all.
To resolve problem with indexes:
In ec_PopupCtrl.pas add public method:
Code: | function TAutoCompletePopup.ListItemIndex(ListIndex: integer): integer;
begin
Result := FComplRender.MapIndex(ListIndex);
end; |
So code in AutoComplete demo will be:
Code: | procedure TForm4.AutoCompletePopup1Change(Sender: TObject);
var Idx: integer;
begin
with AutoCompletePopup1.ListBox do
if ItemIndex = -1 then Idx := -1
else Idx := AutoCompletePopup1.ListItemIndex(ItemIndex);
if Idx <> -1 then
AutoCompletePopup1.ToolHint.Text := AutoCompletePopup1.Items[Idx]
else
AutoCompletePopup1.ToolHint.Text := '';
end; |
Using TAutoCompletePopup.ListBox.Items is not recommended, because this list is empty (except Delphi 5 where virtual list boxes are not supported).
Michael. |
|
Back to top |
|
|
|