将一组项目添加到检查列表框并在之后读取值
Add set of items to checklistbox and read values after
有什么方法可以从清单框中填写和获取 set
项吗?
我做了什么:
TColorItem = (ms_red, ms_blue, ms_green, ms_yellow);
TColorItems = set of TColorItem;
我有一个组件,我可以从TColorItems
中选择
TProperty = class(TCollectionItem)
private
FModuleItem: TColorItems;
procedure SetColorItem(const Value: TColorItems);
published
property ColorTypes: TColorItems read FColorItem write SetColorItem;
procedure SetColorItem(const Value: TColorItems);
begin
FColorItem := Value;
end;
设置(检查)组件中的项目后,我创建了一个表单。
我的表单如下所示:
如果我选中清单框中的任何项目,我希望将 Result
作为 TColorItems
集合:
如果选中红色和绿色,则set
必须是
Result := [ms_red, ms_green]
如果选中蓝色、绿色和黄色:
Result := [ms_blue, ms_green, ms_yellow]
等..
Result
必须是这种[value1, value2]
形式;我想在之后使用它。
声明与 TColorItem
类型配对的字符串数组。
const
ColorItemNames: array [TColorItem] of string = ('Red', 'Blue', 'Green', 'Yellow');
用数组填充 TCheckListBox
对象。
var
ci: TColorItem;
begin
for ci := Low(ColorItemNames) to High(ColorItemNames) do
CheckListBox1.Items.AddObject(ColorItemNames[ci], TObject(ci));
end;
从 TCheckListBox.Items
属性 的 Objects
中获取 TColorItems
的值。
var
i: Integer;
begin
Result := [];
for i := 0 to CheckListBox1.Count-1 do begin
if CheckListBox1.Checked[i] then
Include(Result, TColorItem(CheckListBox1.Items.Objects[i]));
end;
end;
有什么方法可以从清单框中填写和获取 set
项吗?
我做了什么:
TColorItem = (ms_red, ms_blue, ms_green, ms_yellow);
TColorItems = set of TColorItem;
我有一个组件,我可以从TColorItems
TProperty = class(TCollectionItem)
private
FModuleItem: TColorItems;
procedure SetColorItem(const Value: TColorItems);
published
property ColorTypes: TColorItems read FColorItem write SetColorItem;
procedure SetColorItem(const Value: TColorItems);
begin
FColorItem := Value;
end;
设置(检查)组件中的项目后,我创建了一个表单。
我的表单如下所示:
如果我选中清单框中的任何项目,我希望将 Result
作为 TColorItems
集合:
如果选中红色和绿色,则
set
必须是Result := [ms_red, ms_green]
如果选中蓝色、绿色和黄色:
Result := [ms_blue, ms_green, ms_yellow]
等..
Result
必须是这种[value1, value2]
形式;我想在之后使用它。
声明与 TColorItem
类型配对的字符串数组。
const
ColorItemNames: array [TColorItem] of string = ('Red', 'Blue', 'Green', 'Yellow');
用数组填充 TCheckListBox
对象。
var
ci: TColorItem;
begin
for ci := Low(ColorItemNames) to High(ColorItemNames) do
CheckListBox1.Items.AddObject(ColorItemNames[ci], TObject(ci));
end;
从 TCheckListBox.Items
属性 的 Objects
中获取 TColorItems
的值。
var
i: Integer;
begin
Result := [];
for i := 0 to CheckListBox1.Count-1 do begin
if CheckListBox1.Checked[i] then
Include(Result, TColorItem(CheckListBox1.Items.Objects[i]));
end;
end;