Sign in Join

Live chat for Free Pascal, Lazarus, Delphi and every Pascal programmer.

Mailing lists / lazarus / 2009-03

Unable to use method AdvancedCustomDrawItem and AdvancedCustomDrawSubItem

1 message · 1 person ·

Reply by email Subscribe to this list Your subscription

Read-only archive. Use j and k to move between messages.

YanChengyuan

Sorry for my bad englist.
i declared lv as TListView.
lv's viewstyle is vsReport,and i was going to place a progressbar on a column,and that is what a downloader usually looks like.but whatever i did
there is no progressbar on the lv(TListView).Can anybody tell me why? Here are my codes:

Unit Unit2;
{$mode objfpc}{$H+}
Interface

Uses
Classes, Sysutils, Fileutil, Lresources, Forms, Controls, Graphics, Dialogs,

  ComCtrls, StdCtrls;
Type
  { Tform1 }
  Tform1 = Class(Tform)
    Button1: Tbutton;
    lv: TListView;
    Procedure Button1click(Sender: Tobject);
    Procedure Lvadvancedcustomdrawitem(Sender: Tcustomlistview;
      Item: Tlistitem; State: Tcustomdrawstate; Stage: Tcustomdrawstage;
      Var Defaultdraw: Boolean);
    Procedure Lvadvancedcustomdrawsubitem(Sender: Tcustomlistview;
      Item: Tlistitem; Subitem: Integer; State: Tcustomdrawstate;
      Stage: Tcustomdrawstage; Var Defaultdraw: Boolean);
  Private
    { Private Declarations }
  Public
    { Public Declarations }
  End;
Var
  Form1: Tform1;
Implementation

{ Tform1 }

Procedure Tform1.Lvadvancedcustomdrawsubitem(Sender: Tcustomlistview;
  Item: Tlistitem; Subitem: Integer; State: Tcustomdrawstate;
  Stage: Tcustomdrawstage; Var Defaultdraw: Boolean);
var
  r:TRect;
  p:TProgressBar;
Begin
  if SubItem1 then exit;
  r:=item.DisplayRect(drBounds);
  p:=TProgressBar.Create(Self);
  item.Data:=p;
  with p do
  begin
    Parent:=lv;
    left:=lv.left+lv.Column[0].Width;
    width:=lv.Column[1].width;
    top:=r.top;
    height:=r.bottom-r.top;
    smooth:=true;
    Max:=100;
    position:=Random(101);
  end;
End;
Procedure Tform1.Button1click(Sender: Tobject);
var
  li:TListItem;
  r:TRect;
  p:TProgressBar;
Begin
  li:=lv.Items.add;
  li.Caption:='Item '+IntToStr(lv.items.Count);
{  r:=li.DisplayRect(drBounds);
  p:=TProgressBar.Create(Self);
  li.Data:=p;
  with p do
  begin
    Parent:=lv;
    top:=0;
    left:=lv.left+lv.Column[0].Width;
    width:=lv.Column[1].width;
    top:=r.top;
    height:=r.bottom-r.top;
    smooth:=true;
    Max:=100;
    position:=Random(101);
  end;}
End;
Procedure Tform1.Lvadvancedcustomdrawitem(Sender: Tcustomlistview;
  Item: Tlistitem; State: Tcustomdrawstate; Stage: Tcustomdrawstage;
  Var Defaultdraw: Boolean);
var
  r:TRect;
  p:TProgressBar;
Begin
  r:=item.DisplayRect(drBounds);
  p:=TProgressBar.Create(Self);
  item.Data:=p;
  with p do
  begin
    Parent:=lv;
    left:=lv.left+lv.Column[0].Width;
    width:=lv.Column[1].width;
    top:=r.top;
    height:=r.bottom-r.top;
    smooth:=true;
    Max:=100;
    position:=Random(101);
  end;
End;
Initialization
  {$I unit2.lrs}
End.

Regards,
Yan Chengyuan

-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://www.lazarus.freepascal.org/pipermail/lazarus/attachments/20090317/4da86d39/attachment.html

Reply by email