cancel
Showing results for 
Search instead for 
Did you mean: 

TC4 Focuscontrol

Occasional Contributor

TC4 Focuscontrol

Hi, ALL

I have Delphi Form  with the Label (TLabel) and Lookup  (Created in runtime, name random).

I can find label by its caption, I can get object from TLabel.FocusControl.



Function FindParam3(OBJ, ACaption): OLEVaraint;

var I;

  PropArray, ValuesArray;

begin

  PropArray := CreateVariantArray(0, 0);

  ValuesArray := CreateVariantArray(0, 0);

  PropArray[0] := 'Caption';

  ValuesArray[0] := ACaption;

  I := obj.find(PropArray, ValuesArray, 1000);

  if I.Exists then  begin

    Result := i.FocusControl;

  end 

  else begin

    Result := Null;

  end; 

end;



But this object has different interface that I can found from TC object browser.



I needed TestComplete method KEYS and other.

How to typecast FocusControl to TLookup?

Or how to I can get Focuscontrol.NativeDelphiobject.Name (Lookup.name)?

Or other way to get VCL Control with runtime name generation?

6 REPLIES 6
Staff

RE: TC4 Focuscontrol

Hi,



After you obtain your control via FocusControl, call its parent's Find method. Use the NativeDelphiObject.Name property as its first parameter and the Name property as the second. For example:

obj := someOtherObj.FocusControl;

obj := someOtherObj.Parent.Find('NativeDelphiObject.Name', obj.Name);




This will give you TC's wrapper for this control. You need to do this since FocusControl returns a native VCL object which doesn't have properties and methods added by TC.

------
Yuri
TestComplete Customer Care Engineer

Did my reply answer your question? Give Kudos or Accept it as a Solution to help others.
Occasional Contributor

RE: TC4 Focuscontrol

Result := I.FocusControl; 

Result := i.Parent.Find('NativeDelphiObject.Name', Result.Name);



Exception: Undeclared identifier: name



s : WideString.

S := I.FocusControl.Name

Exception: Undeclared identifier: name



But on TC I see property Name and it have a correct value

Smiley Sad



Staff

RE: TC4 Focuscontrol

Hi,



Try inspecting the object returned from FocusControl on a breakpoint (watch in the Evaluate dialog). What properties do you get?

------
Yuri
TestComplete Customer Care Engineer

Did my reply answer your question? Give Kudos or Accept it as a Solution to help others.
Occasional Contributor

RE: TC4 Focuscontrol

Hi

property Name exist.

If I in Evalute dialog enter Result.name and click  Evalute I get "[name : Property does not exist]"

If I in Evalute dialog enter Result.Name and click  Evalute I get correct name.

But in code I wrote "Result.Name" and I get exception Smiley Sad
Occasional Contributor

RE: TC4 Focuscontrol

In Evalute Dialog

Result.ID, Result.FullName

[xxx : Property does not exist]



From Help:

The following methods and properties are common for all processes, windows, controls and onscreen objects.

Common Properties



Common PropertiesCommon PropertiesName Description

_NewEnum Returns an enumerator for the collection of children that belong to the object.

ChildCount Returns the number of child objects of the current object.

Exists Informs whether an object exists in the system.

FullName Specifies the full name that uniquely identifies the object in TestComplete.

Id Returns the ID of the current object.

MappedName Returns the custom name, which is mapped to the original name of the object, as a string.

Name Returns the name of the object as a string.

Parent Returns the parent object of the current one.



Why "Property does not exist"????
Occasional Contributor

RE: TC4 Focuscontrol

Final working code:

Function FindFocusCountrol(OBJ, ACaption);

var I;

  PropArray, ValuesArray;

  s : WideString;

begin

  PropArray := CreateVariantArray(0, 0);

  ValuesArray := CreateVariantArray(0, 0);

  PropArray[0] := 'Caption';

  ValuesArray[0] := ACaption;

  

  I := obj.find(PropArray, ValuesArray, 1);

  if I.Exists then  begin

    Result := i.FocusControl;

    Result := OBJ.VclObject(Result.Name);

  end  

  else begin

    Result := Null;

  end;  

end;
New Here?
Join us and watch the welcome video:
6 / 7 API Testing Mistakes Video
Top Kudoed Authors