質問

私はTCheckListbox(lbServices)で、このコードを使用し、それが正常に動作します。しかしDevExpress社からTcxCheckListBoxでそれは例外を発生させます。

procedure TMaintenanceForm.AfterConstruction;
var
  i: Integer;
  ActionObj: TAction;
begin
  inherited;
  for i := 0 to ServiceActionList.ActionCount-1 do
  begin
    ActionObj := ServiceActionList.Actions[i] as TAction;
    lbServices.Items.AddObject(ActionObj.Caption, ActionObj);
  end;
end;

procedure TMaintenanceForm.btnStopClick(Sender: TObject);
begin
  fContinue := False;
end;

procedure TMaintenanceForm.cmdExecuteSelectedClick(Sender: TObject);
var
  i: Integer;
begin
  Screen.Cursor := crHourGlass;
  try
    for i := 0 to lbServices.Count -1 do
      if lbServices.Selected[i] then
        (lbServices.Items.Objects[i] as TAction).Execute;  // Exception here!!!!
  finally
    Screen.Cursor := crDefault;
  end;
end;

私は、コードlbServices.Count = 12をデバッグする場合。 lbServices.Items.Objects [I]は、リスト内のすべての項目についてはnilです。何がここで間違っているのですか?

役に立ちましたか?

解決

の代わりに、次のコードを使用します:

var
  AItem: TcxCheckListBoxItem;
begin
  AItem := cxCheckListBox1.Items.Add;
  AItem.ItemObject := Action1;
  AItem.Text := Action1.Caption;
end;

...

var
  I: Integer;
begin
  for I := 0 to cxCheckListBox1.Items.Count - 1 do
    if cxCheckListBox1.Items[I].Checked then
      (cxCheckListBox1.Items[I].ItemObject as TACtion).Execute;
end;

他のヒント

TcxCheckListBox.Items

の一切の のオブジェクトのプロパティはありません
ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top