Scripter and the controls provided in Scripter are dependent on built around the VCL counterparts.
Because of this some of the users of my product who have VB6 background are facing one problem and have been requesting me to add a new runtime property to ComboBox/ListBox control(s).
And this property is ItemData which will only store numeric values. As they are coming from VB6 background they are finding it hard and unintuitive to use ComboBox1.Items.AddObject syntax from Basic script.
I am fumbling with the code file ap_ComCtrls.pas to add this property but I am not able to make any headway.
Please help me in adding this runtime only property with read/write access.
Finally now can I compile the TMS Scripter Pro VCL after making changes to the base code?
You can simply define that property as you would do with any new property. You don't need to change ap_ComCtrls for that. Just use DefineClass(TListBox).DefineProperty() and define your ItemData property the way you want: http://www.tmssoftware.biz/business/scripter/doc/web/acessingnon-publishedpropert.html.
Thanks for the code sample.
But I am not able to compile this code:
In Create event I have placed this code:
//Code to add ItemData property to ComboBox control
I have created these two procedures:
procedure TForm1.GetItemDataProc(AMachine: TatVirtualMachine);
With AMachine do
ReturnOutputArg(TListBox(CurrentObject).Items); //<== Error occurs here
procedure TForm1.SetItemDataProc(AMachine: TatVirtualMachine);
With AMachine do
TListBox(CurrentObject):=GetInputArgAsInteger(0); //<== Error occurs here
I need to clarify that the property ItemData that I want to add will be for each Item in the Items collection of ComboBox control not just one single property for the control.
Would it be possible to add a method AddItem(S: string, ItemData: Integer) ?
By doing this now the ComboBox will have two AddItem methods one the default and another to add an Integer value
I hope I am making some sense?
In this case I suggest you create an indexed property, not a regular property. This way your user can access the property using an index (ItemData[Index] for example).