我该如何让我的代码工作? :)我试图制定这个问题,但经过几次失败的尝试后,我认为你们会发现问题的速度比阅读我的'解释'更快。谢谢。使用他的类类型转换TObject?
setCtrlState([ memo1, edit1, button1], False);
_
procedure setCtrlState(objs: array of TObject; bState: boolean = True);
var
obj: TObject;
ct: TClass;
begin
for obj in objs do
begin
ct := obj.ClassType;
if (ct = TMemo) or (ct = TEdit) then
ct(obj).ReadOnly := not bState; // error here :(
if ct = TButton then
ct(obj).Enabled:= bState; // and here :(
end;
end;
不应该在每一种情况下第二类型转换为“TEDIT”,而不是“TMemo”? – Argalatyr 2009-07-04 23:21:04
+0.5表示你必须对每种类型进行演员表演。 +0.5使用“是” – 2009-07-04 23:23:19