출처는 여기
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 |
function FindAnyControl(obj: TWinControl; s: string): TComponent; var x: integer; begin Result := nil; try for x := 0 to obj.ComponentCount - 1 do begin if (AnsiCompareText(s, obj.Components[x].Name) = 0) then Result := obj.Components[x] else if obj.Components[x] is TWinControl then Result := FindAnyControl(TWinControl(obj.Components[x]), s); if (Result <> nil) then break; end; except { eat the exception because we don't care about it } end end; procedure TForm1.Button1Click(Sender: TObject); var lbl : TLabel; begin lbl := FindAnyControl(Form1, 'label1') as TLabel; lbl.Caption := 'test'; end; |