Need help with custom component.

I'm having trouble with a custom listbox component(does not descend form tlistbox or tcustomlistbox), basically I want text normal when not selected and bold when the item is selected. However it is always bold for some reason.

I believe the problem lies in the component source as opposed to my code below but here it is anyway.

Basically umm in the OnDrawItem event I do this:

Procedure TFrmMain.MP3_ListDrawItem(Sender: TObject; ACanvas: TCanvas; Index: SmallInt; Const ARect: TRect; Selected: Boolean);
Begin
 If (Selected) Then ACanvas.Font.Style := [fsBold]
 Else ACanvas.Font.Style := [];
    ACanvas.Brush.Style := bsClear;
    ACanvas.TextOut(ARect.Left,ARect.Top,TCListBox(Sender).Items[Index]);
End;

But the text is always bold whether selected or not. Here isa link to the source of the component if anyone wants to check it out themselves and see what may be wrong. I must be missing something but all looks fine to me.

http://chessoscorner.com/files/CListBox.zip
ChessoAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Pierre CorneliusCommented:
I tested and it worked fine.

Procedure TFrmMain.MP3_ListDrawItem(Sender: TObject; ACanvas: TCanvas; Index: SmallInt; Const ARect: TRect; Selected: Boolean);
Begin
 If (Selected) Then ACanvas.Font.Style := [fsBold]
 Else ACanvas.Font.Style := [];
    ACanvas.Brush.Style := bsClear;
//you don't need this line
//    ACanvas.TextOut(ARect.Left,ARect.Top,TCListBox(Sender).Items[Index]);
End;

You probably forgot to assign the event to the component, e.g.

  CListBox1.OnDrawItem:= MP3_ListDrawItem;

regards
Pierre

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
ChessoAuthor Commented:
Nope the event was assigned but removing the textout and placing the setting of bsClear in only the else statement fixes it up.
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Delphi

From novice to tech pro — start learning today.