http://www.delphibbs.com/delphibbs/dispq.asp?lid=1937809
如何遍历一个集合?
http://www.delphibbs.com/delphibbs/dispq.asp?lid=3438514
如何遍历一个集合
http://www.delphibbs.com/delphibbs/dispq.asp?lid=2650674
请问如何枚举一个集合里和每个元素
----------------------------
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls;
type
TForm1 = class(TForm)
Button1: TButton;
procedure Button1Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
type
TSets = set of (ssA, ssB, ssC, ssD);
function GetSetCount(const V): Byte;
var
D: Byte;
begin
Result := 0;
D := PByte(@V)^;
while D <> 0 do begin
if D and 1 = 1 then
Inc(Result);
D := D shr 1;
end;
end;
procedure TForm1.Button1Click(Sender: TObject);
var
V: TSets;
begin
V := [ssA, ssB, ssD];
Caption := IntToStr(GetSetCount(V));
end;
end.