We help IT Professionals succeed at work.

How do I stop the Type Library form getting ****ed up.

hulken
hulken asked
on
I like to add this to my typelibrary:

function Get_ControlDefault(Index: Integer):IText; safecall;
procedure Set_ControlDefault(Index: Integer;Value: IText); safecall;

    function Get_Item(Index: Integer): IText; safecall;
    procedure Set_Item(Index: Integer; Value: IText); safecall;
    property ControlDefault[Index: Integer]: IText read Get_ControlDefault write Set_ControlDefault; default;
    property Item[Index: Integer]: IText read Get_Item write Set_Item;


Can this be done from the "TypeLibrary Editor"
(that one you get when you do a wiev typelibrary)

and if I just edit my typelibrary manualy. then the editor remove all my changes next time I open it. (or do a rebuild)


How can I stop this behaviour?
Comment
Watch Question

Commented:
of course.

Author

Commented:
What?
Russell LibbySoftware Engineer, Advisory
BRONZE EXPERT
Top Expert 2005

Commented:

hulken,

Yes this can be (and should be) added through the type library editor provided with Delphi. Delphi builds the unit file from the .tlb file, and expects any changes to be made in the type library editor.

In fact, Delphi generates something like this as a comment in the unit created from the .tlb file:

WARNING                                                                    
// -------
// The types declared in this file were generated from data read from a      
// Type Library. If this type library is explicitly or indirectly (via        
// another type library referring to this type library) re-imported, or the  
// 'Refresh' command of the Type Library Editor activated while editing the  
// Type Library, the contents of this file will be regenerated and all        
// manual modifications will be lost.                                        

As to adding the new property:

Select the interface to add the property to, click the property button, and select the read/write menu item from the drop down menu. Set the name and the result type, and then insert a new [in] parameter that is of type integer (for the index). Once the property has been set to what you desire, click the refresh button and then add the logic for the new get/set functions.

Hope this clears some things up,
Russell

Author

Commented:
Ok can you help me out a bit more.

I like to add:

function Get_ControlDefault(Index: Integer): IText; safecall;
    procedure Set_ControlDefault(Index: Integer; Value: IText); safecall;
    function Get_Item(Index: Integer): IText; safecall;
    procedure Set_Item(Index: Integer; Value: IText); safecall;
    property ControlDefault[Index: Integer]: IText read Get_ControlDefault write Set_ControlDefault; default;
    property Item[Index: Integer]: IText read Get_Item write Set_Item;

to the type_library.

You wrote that I should insert a new in parameter. From the modifyer list I can only chose out. not in

Author

Commented:
I dont now how to get the [ ] either....

Author

Commented:
I can't find out how to get the default on the ControlDefault,
You must set dispid = 0 manually for ControlDefault property in Delphi Type library editor.
Software Engineer, Advisory
BRONZE EXPERT
Top Expert 2005
Commented:

Hulken,

Add the properties (read/write) to the type library one at a time.

1.) Add new property, rename it.
2.) Set the "Type" to IText (must be in the dropdown of valid types, or your missing a type libarary in the uses)
3.) On the parameters tab click the Add button and change the name of the new param to Index, make sure param is in the first row, otherwise click "Move Up" button.
4.) Change the Index param type to long, and change the modifier to in. The in modifier should be available, if not click the [...] button to get the Parameter Flag window. In, out, retval, lcid, optional, and has default value should be shown as check boxes.
5.) Make sure both the get/set property definitions now show the added param.
6.) Click the refresh implementation button and check for any errors that occurred. (Right click on tree view and select view errors)
7.) Go check the delphi unit for the newly added get_item and set_item functions

Good call for SChertkov on DispID of zero, which is DISPID_VLAUE (meaning the default member)

Other constant values for DISPID are

  DISPID_VALUE       = 0;
  DISPID_UNKNOWN     = -1;
  DISPID_PROPERTYPUT = -3;
  DISPID_NEWENUM     = -4;
  DISPID_EVALUATE    = -5;
  DISPID_CONSTRUCTOR = -6;
  DISPID_DESTRUCTOR  = -7;
  DISPID_COLLECT     = -8;

Let me know if you run into further problems
Russell


Explore More ContentExplore courses, solutions, and other research materials related to this topic.