我該如何讓我的代碼工作? :)我試圖制定這個問題,但經過幾次失敗的嘗試後,我認爲你們會發現問題的速度比閱讀我的'解釋'更快。謝謝。使用他的類類型轉換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