Forum Discussion

Lyna's avatar
Lyna
Occasional Contributor
14 years ago

Edit a property which is and object (with ODT)

Hi,



I'm currently learning how to create classes and objects programmatically but i have a problem.

I create Classes with this procedure :



procedure CreateClasses;

var

  menu,menu_item,find_properties;



begin

  ODT.Data.Clear;

  ODT.Classes.Clear;

 

  find_properties := ODT.Classes.Declare('FindProperties');

  find_properties.AddProperty('Prop');

  find_properties.AddProperty('Values');

  find_properties.AddProperty('Parent');

  find_properties.AddProperty('Depth');

  find_properties.AddMethod('GetObject','DescriptionMethodes.FindProperties_GetObject');

 

  menu_item := ODT.Classes.Declare('MenuItem');

  menu_item.AddProperty('Index');

  menu_item.AddProperty('Name');

  menu_item.AddPropOfArrayType('SubMenu');



  menu := ODT.Classes.Declare('Menu');

  menu.AddPropOfArrayType('Items');

  menu.AddProperty('Name');

  menu.AddPropOfClassType('Properties','FindProperties');  

 







end;




Then to insert Data i use this method :



procedure CreateDatas;

var

  data,arr,menu,menu_item,properties;

begin

  ODT.Data.Clear;

  data := ODT.Data.AddGroup('MenuData');

 

  arr := data.AddVarOfArrayType('Menus');

  menu := arr.AddItemOfClassType('Menu');

  menu.Name := 'Nom_de_mon_Menu';

 

  menu_item := menu.Items.AddItemOfClassType('MenuItem');

  menu_item.Index := 0;

  menu_item.Name := 'Ouvrir';

 

  menu.Properties.Parent := 'Georgette';

  menu.Properties.Prop := ['WndCaption','FullName','Visible'];  

  menu.Properties.Values := ['Nom_fenetre','Window.Truc.Machin.Bidule','True'];

 

  menu.Properties.Depth := 3;



  EnableAllMethods(menu);  



end;








The creation of classes works, but when i insert my datas, At the line menu.Properties.Parent := 'Georgette'; an error occurs, specifying that i'm trying to put a value in a read-only property...



How can i set the value of this property ? I can't find the solution on the support of TestComplete.





Thanks

3 Replies


  • Hi Ell,





    When you create an instance of an ODT class, this instance is wrapped by an instance of the 'Class' object. You can find documentation on this object in the Class Object help topic. When you address a property of a method of your ODT class by using the '<ClassObj>.<MyProperty>' syntax, the instance of the Class object invokes the corresponding property or method of the ODT class automatically. However, the Class object has a number of its own properties and methods and if your ODT class has a property with the name of one of the native properties of the Class object, a name conflict occurs. In this case, TestComplete invokes the native property or method of the Class object instead of a property or method of your ODT class.





    In your case, the conflicting property is 'Properties'. There are two solutions:

    1. Rename the 'Properties' property in your ODT class.

    2. Access this property via the native 'Properties' property in the following way:



      menu.Properties('Properties').Value.Parent := 'Georgette'; 

      menu.Properties('Properties').Value.Prop := ['WndCaption','FullName','Visible'];  

      menu.Properties('Properties').Value.Values := ['Nom_fenetre','Window.Truc.Machin.Bidule','True'];
  • Lyna's avatar
    Lyna
    Occasional Contributor
    I chose to change the name of my property Properties in Props but I know have an other problem.

    I want to access to the property Props using Properties :



    menu.Properties('Prop')





    But I obtain this error : "Unknown name. Properties ".





    I don't understand because when i use menu.Props it works perfectly.





    Edit : I didn't use Value correctly, i understood my problem, sorry for this useless post =)

  • Hi Ell,





    The below code works fine for me. Could you please post here the code that does not work?

    procedure CreateClasses;

    var

      menu,menu_item,find_properties;





    begin

      ODT.Data.Clear; 

      ODT.Classes.Clear;

      

      find_properties := ODT.Classes.Declare('FindProperties');

      find_properties.AddProperty('Prop');

      find_properties.AddProperty('Values');

      find_properties.AddProperty('Parent');

      find_properties.AddProperty('Depth'); 

      find_properties.AddMethod('GetObject','DescriptionMethodes.FindProperties_GetObject'); 

      

      menu_item := ODT.Classes.Declare('MenuItem');

      menu_item.AddProperty('Index');

      menu_item.AddProperty('Name');

      menu_item.AddPropOfArrayType('SubMenu');





      menu := ODT.Classes.Declare('Menu');

      menu.AddPropOfArrayType('Items');

      menu.AddProperty('Name');

      menu.AddPropOfClassType('Props','FindProperties');  

      





    end;









    procedure CreateDatas;

    var

      data,arr,menu,menu_item,properties;

    begin

      ODT.Data.Clear;

      data &colon;= ODT.Data.AddGroup('MenuData');

      

      arr := data.AddVarOfArrayType('Menus');

      menu := arr.AddItemOfClassType('Menu'); 

      menu.Name := 'Nom_de_mon_Menu';

      

      menu_item := menu.Items.AddItemOfClassType('MenuItem');

      menu_item.Index := 0;

      menu_item.Name := 'Ouvrir';





      menu.Properties('Props').Value.Parent := 'Georgette'; 

      menu.Properties('Props').Value.Prop := ['WndCaption','FullName','Visible'];  

      menu.Properties('Props').Value.Values := ['Nom_fenetre','Window.Truc.Machin.Bidule','True'];

      

      menu.Properties('Props').Value.Depth := 3;

                           

      EnableAllMethods(menu);  





    end;