Forum Discussion

Bertrand's avatar
Bertrand
Occasional Contributor
13 years ago

Getting a delphi derived component parent class

Hi ,



I'm testing an application written in Delphi .

I get the delphi component like this;



var MyComponent=MyWindow.Find('Name','VCLObject(Component)',30);



Then i try to get the derived component base class:



var type= MyComponent.ClassType();

var base=type.ClassParent();



But I have the result:type='undefined'.



(I found the ClassType() and ClassParent() methods using TestComplete Object inspector.)



Can anyone help me?

7 Replies

  • tristaanogre's avatar
    tristaanogre
    Esteemed Contributor
    Is the component a direct child of MyWindow?  If so, you could do the following



    var MyComponent = MyWindow.WaitVCLObject("ComponentName", 10000)




    I suspect that the problem is that your "Find" call is not actually finding the component and is returning an empty object.



    Personally, when using the "Find" method, I tend not to use "Name" but use, instead, other properties of the component to find what I'm looking for.  You might want to try using other properties and arrays of properties for your find method to see if you can get to your component.
  • Bertrand's avatar
    Bertrand
    Occasional Contributor
    MyComponent is a direct child of MyWindow.

    And when I inspect the object i can find that it's not empty.

    What do you suggest?

    Thanks.
  • tristaanogre's avatar
    tristaanogre
    Esteemed Contributor
    I suggest using WaitVCLObject to wait for the object to appear and then check the property in code, pretty much like I suggested above.
  • Bertrand's avatar
    Bertrand
    Occasional Contributor
    Ok I will try it at work tomorrow morning and tell you if it works.

    Thanks.
  • Bertrand's avatar
    Bertrand
    Occasional Contributor
    Hi,

    I tried WaitVCLObject and here is my code:



    var MyComponent=MyWindow.WaitVCLObject("MyComponent",-1);

    var type=MyComponent.ClassType();

    var base=type.ClassParent();



    But I still get 'type==undefined'

    I Inspected MyComponent and here is the result(ScreenCapture1).



    Thanks.
  • AlexKaras's avatar
    AlexKaras
    Champion Level 3
    Hi Bertrand,



    > Then i try to get the derived component base class:

    If you are talking about classes hierarchy from the source code point of view (e.g. TObject -> TWindow -> TButton -> TBitButton -> ...) than for the native Windows applications it is not possible to find the name of the parent class during run-time because this information is needed only by the compiler during compile-time and is not saved in the debug information.



    If you are looking for the run-time parent of the given object in the hierarchy shown in the TestComplete's Object Spy, then you can use the .Parent property of the given object.
  • Bertrand's avatar
    Bertrand
    Occasional Contributor
    Hi Alexei,

     Yes ,I was talking about classes hierarchy from the source code point of view.

     Tanks for your help