unit Unit1;interfaceuses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, StdCtrls, CheckLst;type
    TForm1 = class(TForm)
    ChkLst: TCheckListBox;
    Label1: TLabel;
    Label2: TLabel;
    EdItEn: TEdit;
    Label3: TLabel;
    EdState: TEdit;
    EdChk: TEdit;
    procedure ChkLstClick(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
    //type TCheckBoxState=(cbUnchecked,cbChecked,cbGrayed);
  
    Function GetArrNub(P:array of boolean):string;
    Function GetChkNum(P:array of TCheckBoxState):string;
  end;//property State[Index:Integer]:TCheckBoxState;
var
  Form1: TForm1;
  //property State[index:Integer]:TCheckBoxState;
  //State[Index:Integer]:TCheckBoxState;implementation{$R *.dfm}
Function TForm1.GetArrNub(P:array of boolean):string;
var i:Integer;
    s:string;
begin
  s:='';
  for i:=Low(p) to High(p) do
  begin
    case P[i] of
      True:s:=s+'T';
      false:s:=s+'F';
    end;
  end;
  Result:=s;
end;type TCheckBoxState=(cbUnchecked,cbChecked,cbGrayed);
property State[Index:Integer]:TCheckBoxState;       //这行老是报错
Function TForm1.GetChkNum(P:array of TCheckBoxState):string;
var i:Integer;
    s:string;
begin
  s:='';
  for i:=0 to High(P)-Low(P) do
  begin
    case P[i] of
      cbunchecked: s:=s+'U';
      cbChecked:   s:=s+'C';
      cbGrayed:    s:=s+'G';
    end;
  end;
  Result:=s;
end;  procedure TForm1.ChkLstClick(Sender: TObject);
var p:array of boolean;
    s:array of TCheckBoxState;
    i:Integer;
begin
  setLength(P,ChkLst.Items.Count);
  for i:=0 to ChkLst.Items.Count-1 do
   p[i]:=ChkLst.checked[i];
  EdChk.text:=GetArrNub(p);
  for i:=0 to ChkLst.Items.Count-1 do
   p[i]:=ChkLst.ItemEnabled[i];
  EdItEn.Text:=GetArrNub(p);
  for i:=0 to ChkLst.Items.Count-1 do
   s[i]:=ChkLst.State[i];
  EdState.Text:=GetChkNum(s);
end;end.请问各位“大虾”属性定义type TCheckBoxState=(cbUnchecked,cbChecked,cbGrayed);应该放在哪里?
property State[Index:Integer]:TCheckBoxState;声明又应该放在哪里?

解决方案 »

  1.   

    type
        TCheckBoxState=(cbUnchecked,cbChecked,cbGrayed);  //放在这里    TForm1 = class(TForm)
        ChkLst: TCheckListBox;
        Label1: TLabel;
        Label2: TLabel;
        EdItEn: TEdit;
        Label3: TLabel;
        EdState: TEdit;
        EdChk: TEdit;
        procedure ChkLstClick(Sender: TObject);
      private
        { Private declarations }
      public
        { Public declarations }
        //type TCheckBoxState=(cbUnchecked,cbChecked,cbGrayed);
      

  2.   

    没错hansome(连环)说地不错!
    type
        TCheckBoxState=(cbUnchecked,cbChecked,cbGrayed);  //放在这里    TForm1 = class(TForm)
        ChkLst: TCheckListBox;
        Label1: TLabel;