Recent

Author Topic: [SOLVED] TListBox OnDrawItem problems  (Read 4016 times)

JD

  • Hero Member
  • *****
  • Posts: 1848
[SOLVED] TListBox OnDrawItem problems
« on: May 05, 2015, 11:36:51 am »
Hi there everyone,

I'm trying to port some code from Delphi to Lazarus & part of it is code that allow writing coloured lines to a ListBox. The code in question is as shown below:

Code: [Select]
procedure TfrmServeur.lbxProcessesDrawItem(Control: TWinControl;
  Index: Integer; ARect: TRect; State: TOwnerDrawState);
begin
  // This draws the items in the Process log in colors to allow quick
  // inspection
  with Control as TListBox do
  begin
    Canvas.Brush.Color := Color;
    Canvas.FillRect(Rect);                                    <-------- ERROR HERE
    Canvas.Font.Color := TColor(Items.Objects[Index]);
    Canvas.TextOut(Rect.Left + 2, Rect.Top, Items[Index]);     <-------- ERROR HERE
  end;
end;

procedure TfrmServeur.Log(Msg: string; AColor: TColor);
begin
  // Simply adds a new item to the process log and then makes it the
  // currently selected item.
  lbxProcesses.Items.AddObject(Msg, Pointer(Color));            <-------- ERROR HERE
  lbxProcesses.ItemIndex := lbxProcesses.Items.Count - 1;
end;

The first two errors say Error: Wrong number of parameters specified for call to "Rect" and the last error says Error: Incompatible type for arg no. 2: Got "Pointer", expected "TObject".

I would appreciate your help in resolving these errors.

JD

« Last Edit: May 05, 2015, 01:01:49 pm by JD »
Windows - Lazarus 2.1/FPC 3.2 (built using fpcupdeluxe),
Linux Mint - Lazarus 2.1/FPC 3.2 (built using fpcupdeluxe)

mORMot; Zeos 8; SQLite, PostgreSQL & MariaDB; VirtualTreeView

korba812

  • Sr. Member
  • ****
  • Posts: 394
Re: TListBox OnDrawItem problems
« Reply #1 on: May 05, 2015, 12:07:08 pm »
Change "Rect" to "ARect"

JD

  • Hero Member
  • *****
  • Posts: 1848
Re: TListBox OnDrawItem problems
« Reply #2 on: May 05, 2015, 12:10:39 pm »
Change "Rect" to "ARect"

I feel so stupid. Now I see how obvious it was. The parameter was ARect. Thanks a lot for that. It solves the first two errors; now for the one on Pointer(TColor):D
Windows - Lazarus 2.1/FPC 3.2 (built using fpcupdeluxe),
Linux Mint - Lazarus 2.1/FPC 3.2 (built using fpcupdeluxe)

mORMot; Zeos 8; SQLite, PostgreSQL & MariaDB; VirtualTreeView

korba812

  • Sr. Member
  • ****
  • Posts: 394
Re: TListBox OnDrawItem problems
« Reply #3 on: May 05, 2015, 12:29:15 pm »
Have you tried TObject instead of Pointer?

lbxProcesses.Items.AddObject(Msg, TObject(Color));

JD

  • Hero Member
  • *****
  • Posts: 1848
Re: TListBox OnDrawItem problems
« Reply #4 on: May 05, 2015, 12:57:44 pm »
Have you tried TObject instead of Pointer?

lbxProcesses.Items.AddObject(Msg, TObject(Color));

Yes I just did & it worked. Thanks a lot.
Windows - Lazarus 2.1/FPC 3.2 (built using fpcupdeluxe),
Linux Mint - Lazarus 2.1/FPC 3.2 (built using fpcupdeluxe)

mORMot; Zeos 8; SQLite, PostgreSQL & MariaDB; VirtualTreeView

 

TinyPortal © 2005-2018