我是现场写代码,有不准确的地方,原谅则个:for i := 0 to self.ComponentCount - 1 dobegin if self.Components is TMemo then begin MemoTemp := self.Components as TMemo; if MemoTemp.Text = '' then begin {do sth} end; end else if self.Components is TEdit then begin EditTemp := self.Components as TEdit ; if EditTemp .Text = '' then begin {do sth} end; end; end;
uses typinfofor i := 0 to self.ComponentCount - 1 dobegin if (GetPropInfo(Components, 'text') <> nil) and (GetPropValue(Components, 'text') <> '') then begin // do sth end;
草原骏马,你的代码还可以写为:for i := 0 to self.ComponentCount - 1 dobegin if self.Components is TCustomEditthen begin customEdit := self.Components as TCustomEdit; if customEdit.Text = '' then begin {do sth} end; end; end; TMemo和TEdit,都是从TCustomEdit继承下来的。terry_zhou82,你说的Sender,是指Event事件的触发者,例如Button的OnClick中,Sender就是指当前button,在这里这种方式不适用。