function TGUITestCase.FindControl(Comp: TComponent; const CtlName: string): TControl;
function DoFind(C :TComponent; const CName :string) :TControl;
var
i: Integer;
begin
Result := nil;
i := 0;
while (Result = nil) and (i < C.ComponentCount) do
begin
with C do
begin
if (Components[i] is TControl)
and (UpperCase(Components[i].Name) = CName) then
Result := Components[I] as TControl
else
Result := DoFind(Components[I], CName);
end;
Inc(i);
end;
end;
begin
Assert(Trim(CtlName) <> '', 'No control name');
Result := DoFind(Comp, UpperCase(CtlName));
Assert(Result <> nil, Format('Control named "%s" not found', [CtlName]));
End; |