小问题!快!快!怎样求出CheckListBox里选择了几个?(15分)

  • 主题发起人 主题发起人 asdqwe
  • 开始时间 开始时间
A

asdqwe

Unregistered / Unconfirmed
GUEST, unregistred user!
CheckListBox里有多项内容,怎样求出选择的个数,保存到一个变量里?
 
procedure TForm1.Button1Click(Sender: TObject);
var
n,i:integer;
begin
n:=0;
for i:=0 to checklistbox1.Count -1do
if checklistbox1.Checked then
inc(n);
showmessage(inttostr(n));
end;
 
刚编好的………
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls, CheckLst;
type
TForm1 = class(TForm)
CheckListBox1: TCheckListBox;
Button1: TButton;
procedure Button1Click(Sender: TObject);
procedure CheckListBox1Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;

var
Form1: TForm1;
i:integer;
implementation
{$R *.dfm}
procedure TForm1.Button1Click(Sender: TObject);
begin
showmessage(inttostr(i));
end;

procedure TForm1.CheckListBox1Click(Sender: TObject);
begin
if CheckListBox1.Checked[CheckListBox1.ItemIndex] then
inc(i)
else
dec(i);
end;

end.
 
多人接受答案了。
 

Similar threads

后退
顶部