Home > Back-end >  Questions about the collection of elements
Questions about the collection of elements

Time:10-12

Hello, I ask a question on the set:
I rarely use collection, multi-purpose enumeration, now I need to use, but some problems is not clear,
1. How do you know how many elements from the set,
2. How can you list all the elements of a set of values,

Such as collection:
Var se: the set of Char;
Or
Type ca=(One, Two, Three);
Var num: the set of ca;

That how to list the set all the values in the se or num?

Need to write a function,

CodePudding user response:

 
Var
Cs: the set of Char;
C: Char;
Num: Integer;
The begin
Num:=0;
Cs: [='a'... 'z', 'a'. The 'z', '0'). '9'].
For c:=Low (Char) to High (Char) do
If c in cs then
The begin
Inc (num);
ShowMessage (Format (' the first element=% d % s', [c] num,));
end;
ShowMessage (Format (' there are % d elements' (num)));
end;

CodePudding user response:

"How can you list all the elements of a set of values,"
The question is a bit strange, to understand the set is the set of mathematical

CodePudding user response:

The new version (2005?) A for [c] in [chars] do traverse the usage

CodePudding user response:

Thank you, the key is my collection is what do not know, want to write a generic method to become,

CodePudding user response:

Use method: read RTTI! But it's hard to do,,
  • Related