procedure TForm1.Button1Click(Sender: TObject);
type
AAA = set of 1..5;
var
SS: AAA;
begin
if 4 in SS then Showmessage('111');
end;
//问题1:if 后面的数字如果<4,就没有Showmessage窗口,为什么?procedure TForm1.Button1Click(Sender: TObject);
type
AAA = set of (a, b, f, n, m);
var
SS: AAA;
begin
if b in SS then Showmessage('111');
end;
//问题2:为什么不弹出Showmessage窗口。
谢谢大家。
type
AAA = set of 1..5;
var
SS: AAA;
begin
if 4 in SS then Showmessage('111');
end;
//问题1:if 后面的数字如果<4,就没有Showmessage窗口,为什么?procedure TForm1.Button1Click(Sender: TObject);
type
AAA = set of (a, b, f, n, m);
var
SS: AAA;
begin
if b in SS then Showmessage('111');
end;
//问题2:为什么不弹出Showmessage窗口。
谢谢大家。
ss := [3, 4];
if 4 in SS then Showmessage('111');在 2 中,AAA 是一个类型,SS 是 AAA 类型的变量,这里的 SS 没有赋值,是空集合,不存在任何元素,所以不弹出 Message 窗口。
type
AAA = set of 1..5;
var
SS: AAA;
begin
ss:=[1..5];
if 4 in SS then Showmessage('111');
end;
在集合变量没有进行复值之前此集合变量是一个不可预知的值
比如:
procedure TForm1.Button1Click(Sender: TObject);
type
AAA = set of 1..5;
var
SS: AAA;
begin
if 5 in SS then Showmessage('111');
end;
这样会弹出消息框。在我的机器上。
但是加了代码之后就没有了消息框。
procedure TForm1.Button1Click(Sender: TObject);
type
AAA = set of 1..5;
var
SS: AAA;
begin
ShowMessage('OK');
if 5 in SS then Showmessage('111');
end;
谢谢 CloneCenter(复制中心) 的评论。
dickeybird888(于伟刚) 是不是快升级了,这么着急。放心我结帖率100%。
不知道大家还有没有意见,下午结帖。
type
AAA = set of 1..5;
var
SS: AAA;
begin
if 4 in SS then Showmessage('111');
end;
//问题1:if 后面的数字如果<4,就没有Showmessage窗口,为什么?
答:这里没有初始化,做这种判断没有意义。集合属于结构类型,所以常规来讲集合名称是一个地址。至于楼上提到的不初始化判断为真,我看看,以前从来没有注意到这种情况!procedure TForm1.Button1Click(Sender: TObject);
type
AAA = set of (a, b, f, n, m);
var
SS: AAA;
begin
if b in SS then Showmessage('111');
end;
//问题2:为什么不弹出Showmessage窗口。答:不初始化如何判断,而且你这里的判断也是个错误的判断
集合SS的元素类型应该是枚举类型,而不是单独一个b!
如果你这里初始化,写SS:=[a,b,d],马上报错!
但写SS:=[(c),(e)]则是正确的.....