Solved

Delphi combobox list items refresh/delete/match index

Posted on 2011-03-04
4
1,871 Views
Last Modified: 2012-05-11
with calc do
  begin
  if portLen > 1 then
    Items.add('text1');
  if portLen > 2 then
    Items.add('text2');
  end;
end;

Open in new window


Problem is that the code in this procedure may be referenced multiple times and every time it is referenced it adds more items to the bottom of the combobox list. What I need to do is either delete the list and start over, or match the text to an index so I can populate the combobox if certain conditions are true, or something of that sort.

Or maybe being able to hide the items in the drop down based on certain conditions? This may be the most elegant solution, but I cannot figure out how to do it.

Any help would be appreciated. Thank you!
0
Comment
Question by:keats88
  • 3
4 Comments
 
LVL 32

Accepted Solution

by:
ewangoya earned 125 total points
ID: 35040349
call procedure clear


with calc do
begin
  Clear;
  if portLen > 1 then
    Items.add('text1');
  if portLen > 2 then
    Items.add('text2');
  end;
end;

Open in new window

0
 
LVL 32

Expert Comment

by:ewangoya
ID: 35040355
sorry, items.Clear
with calc do
begin
  Items.Clear;
  if portLen > 1 then
    Items.add('text1');
  if portLen > 2 then
    Items.add('text2');
  end;
end;

Open in new window

0
 
LVL 32

Assisted Solution

by:ewangoya
ewangoya earned 125 total points
ID: 35040372
If you want to check whether an item is already in the list, you can use indexof like this
with calc do
begin
  if (portLen > 1) and (Items.IndexOf(text1) < 0) then
    Items.add('text1');
  if (portLen > 2) and (Items.IndexOf(text2) < 0) then
    Items.add('text2');
  end;
end;

Open in new window

0
 

Author Closing Comment

by:keats88
ID: 35040467
Much easier solution than I expected. I should have figured there was a function like Clear out there.

[code]Clear;[/code]

The above worked just fine.
0

Featured Post

ScreenConnect 6.0 Free Trial

Discover new time-saving features in one game-changing release, ScreenConnect 6.0, based on partner feedback. New features include a redesigned UI, app configurations and chat acknowledgement to improve customer engagement!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article explains how to create forms/units independent of other forms/units object names in a delphi project. Have you ever created a form for user input in a Delphi project and then had the need to have that same form in a other Delphi proj…
Introduction I have seen many questions in this Delphi topic area where queries in threads are needed or suggested. I know bumped into a similar need. This article will address some of the concepts when dealing with a multithreaded delphi database…
This Micro Tutorial will teach you how to censor certain areas of your screen. The example in this video will show a little boy's face being blurred. This will be demonstrated using Adobe Premiere Pro CS6.
Nobody understands Phishing better than an anti-spam company. That’s why we are providing Phishing Awareness Training to our customers. According to a report by Verizon, only 3% of targeted users report malicious emails to management. With compan…

777 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question