Solved

ListBox, how to?

Posted on 2013-12-11
4
325 Views
Last Modified: 2014-01-21
Hello Guys,

I need a clue how to do something like this:

I have a lisbox on my form with 20 lines, some lines are painted in color font clRed and other clblack.

How can I count how many lines I have in my listbox in clred color font?

Thanks
Alex
0
Comment
Question by:hidrau
4 Comments
 
LVL 26

Accepted Solution

by:
Sinisa Vuk earned 500 total points
ID: 39713344
Each listbox item is stored in TStrings list. Item can be stored in with some additional parameter as TObject (integer, like Tcolor is integer too):
listbox.Items.AddObject('item in red', TObject(clRed));
listbox.Items.AddObject('item in red', TObject(clBlack));
....

Open in new window


later you can check for this additional parameter (and even check when drawing in some of OnDraw events):
for i:=0 to listbox.Items.Count-1 do
begin
  if listbox.Items.Objects[i] = TObject(clRed) then ...
  if listbox.Items.Objects[i] = TObject(clBlack) then
end;

Open in new window

0
 
LVL 19

Expert Comment

by:MerijnB
ID: 39713429
How did the items become red? Probably because you painted them red? From what information did you decide to make them red? Can't you look in that information to count?
0
 
LVL 37

Expert Comment

by:Geert Gruwez
ID: 39713478
or the other way around:

how did you paint them black > the_number_of_blacks
to find the reds: listbox.count - the_number_of_blacks
0
 
LVL 1

Author Closing Comment

by:hidrau
ID: 39796608
thanks for the idea :)
0

Featured Post

3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

Question has a verified solution.

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

The uses clause is one of those things that just tends to grow and grow. Most of the time this is in the main form, as it's from this form that all others are called. If you have a big application (including many forms), the uses clause in the in…
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…
Along with being a a promotional video for my three-day Annielytics Dashboard Seminor, this Micro Tutorial is an intro to Google Analytics API data.
Two types of users will appreciate AOMEI Backupper Pro: 1 - Those with PCIe drives (and haven't found cloning software that works on them). 2 - Those who want a fast clone of their boot drive (no re-boots needed) and it can clone your drive wh…

809 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