1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39
| const
wm_changecombolistitems = WM_USER+101;
...
procedure Message_UpdateComboBoxListItems(var Msg: TMessage); message wm_changecombolistitems;
...
procedure TForm1.ComboBox1Change(Sender: TObject);
begin
PostMessage(self.handle, wm_changecombolistitems, 0, 0);
end;
procedure TForm1.Message_UpdateComboBoxListItems(var Msg: TMessage);
var
i: integer;
selstart_, sellength_: integer;
text_: string;
begin
selstart_ := ComboBox1.SelStart;
sellength_ := ComboBox1.SelLength;
text_ := ComboBox1.Text;
ComboBox1.Items.Clear;
for i := 0 to ComboStrings.Count - 1 do
begin
if (text_ = '') or (Pos(text_, ComboStrings[i]) <> 0) then
ComboBox1.Items.Add(ComboStrings[i]);
end;
i := ComboBox1.Items.Count;
if i > 10 then i := 10;
ComboBox1.DroppedDown:=False;
ComboBox1.DropDownCount := i;
ComboBox1.DroppedDown:=True;
ComboBox1.Text := text_;
ComboBox1.SelStart := selstart_;
ComboBox1.SelLength := sellength_;
end; |
Partager