有任何方法来计算组件中的“真”集项吗?
我所做的:
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;该组件具有大量的TCollectionItem,所有的项都有不同的颜色类型。(组件连接到主窗体上的复选框)
例如:
AColorItem
BColorItem
我想数一数“真实的状态”。如果计数> 1,我想做点什么.
TProperty位于具有Item属性的TCollection中.
我可以用.
var
C: integer
vItem: TColorItem
begin
for ...
PropertyCollection.Items[C].ColorTypes谢谢你的帮助!
发布于 2016-02-24 17:06:49
您可以通过将该集与空集[]进行比较来检查它是否为空集。您可以使用一个函数来计算项目数(如下所示):
program Project1;
{$APPTYPE CONSOLE}
uses SysUtils;
type
TColorItem = (ms_red, ms_blue, ms_green, ms_yellow);
TColorItems = set of TColorItem;
procedure WriteSetContents(const AColorItems : TColorItems);
begin
WriteLn('Set contains...');
if AColorItems = [] then begin
WriteLn('Nothing');
Exit;
end;
if ms_red in AColorItems then WriteLn('Red');
if ms_blue in AColorItems then WriteLn('Blue');
if ms_green in AColorItems then WriteLn('Green');
if ms_yellow in AColorItems then WriteLn('Yellow');
end;
function GetSetCount(const AColorItems : TColorItems) : integer;
var
ci : TColorItem;
begin
result := 0;
for ci := Low(TColorItem) to High(TColorItem) do
if ci in AColorItems then Inc(result);
end;
var
cis : TColorItems;
begin
cis := [];
WriteLn(Format('Set has %d Items', [GetSetCount(cis)]));
WriteSetContents(cis);
WriteLn;
cis := cis + [ms_red];
WriteLn(Format('Set has %d Items', [GetSetCount(cis)]));
WriteSetContents(cis);
WriteLn;
cis := cis + [ms_green, ms_yellow];
WriteLn(Format('Set has %d Items', [GetSetCount(cis)]));
WriteSetContents(cis);
ReadLn;
end.https://stackoverflow.com/questions/35608310
复制相似问题