Forum Discussion

bodyguard's avatar
bodyguard
Occasional Contributor
15 years ago

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

  • 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.

  • bodyguard's avatar
    bodyguard
    Occasional Contributor
    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

    :(



  • Hi,



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

  • bodyguard's avatar
    bodyguard
    Occasional Contributor
    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 :(
  • bodyguard's avatar
    bodyguard
    Occasional Contributor
    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"????
  • bodyguard's avatar
    bodyguard
    Occasional Contributor
    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;