How to gaing access to a Property of an object in a TObjectList.

I have the next classes into a File:

TConfigCompProps = class(TObject)
FCD_COMPONENT :string;
FDS_COMPONENT :string;
FQTY_QUANTITY :Double;
FFRONT :Integer;
FDEPTH :Integer;
FTHICK :Integer;
FCD_COLOR :string;
FPACKAGE :Integer;
FPROGRAM_ID :String;
FPRI_UNIT :Double;
FEXPLANATION :string;
published
property CD_COMPONENT :string read FCD_COMPONENT write FCD_COMPONENT;
property DS_COMPONENT :string read FDS_COMPONENT write FDS_COMPONENT;
property QTY_QUANTITY :Double read FQTY_QUANTITY write FQTY_QUANTITY;
property FRONT :Integer read FFRONT write FFRONT ;
property DEPTH :Integer read FDEPTH write FDEPTH ;
property THICK :Integer read FTHICK write FTHICK ;
property CD_COLOR :string read FCD_COLOR write FCD_COLOR ;
property PACKAGE :Integer read FPACKAGE write FPACKAGE ;
property PROGRAM_ID :String read FPROGRAM_ID write FPROGRAM_ID ;
property PRI_UNIT :Double read FPRI_UNIT write FPRI_UNIT ;
property EXPLANATION :string read FEXPLANATION write FEXPLANATION ;
end;

TConfigCompList = class(TObjectList)
private
protected
procedure SetComponent(Index :Integer; Item: TConfigCompProps);
function GetComponent(Index :Integer):TConfigCompProps;
public
property Components[Index :Integer]:TConfigCompProps read GetComponent write SetComponent; default;
published
constructor Create; overload;
function Add(Obj :TConfigCompProps):Integer; overload;
procedure Insert(Index :Integer; Obj :TConfigCompProps);
end;


In the Object from which I create the script I have the next declaration:

FComponents :TConfigCompList;
property Component :TConf......

I have a method in which I feed with data this structure:

procedure TConfigCompOrm.FeedScriptObject;
var Component :TConfigCompOrm;
ConfigComp :TConfigCompProps;
begin
FComponents := TConfigCompList.Create;
for Component in FConfiguration do begin
ConfigComp := TConfigCompProps.Create;
ConfigComp.CD_COMPONENT := Component.CD_COMPONENT.AsString ;
ConfigComp.DS_COMPONENT := Component.DS_COMPONENT.AsString ;
ConfigComp.QTY_QUANTITY := Component.QTY_QUANTITY.AsExtended;
ConfigComp.FRONT := Component.FRONT.AsInteger ;
ConfigComp.DEPTH := Component.DEPTH.AsInteger ;
ConfigComp.THICK := Component.THICK.AsInteger ;
ConfigComp.CD_COLOR := Component.CD_COLOR.AsString ;
ConfigComp.PACKAGE := Component.PACKAGE.AsInteger ;
ConfigComp.PROGRAM_ID := Component.PROGRAM_ID.AsString ;
ConfigComp.PRI_UNIT := Component.PRI_UNIT.AsExtended ;
ConfigComp.EXPLANATION := Component.EXPLANATION.AsString ;
FComponents.Add(Component);
end;
end;



Before execute the Script I have the next adds....

FeedScriptObject;
{ add new class inherited from TObject }
with Script.AddClass(TConfigCompProps, 'TObject') do begin
{ Don't has public methods }
end;

with Script.AddClass(TConfigCompList, 'TObjectList') do begin
{ add public methods }
AddProperty('Count', 'Integer', GetProp, nil);
{ Add Index property Components[Index :Integer]:TConfigCompProps }
AddIndexProperty ('Components', 'Integer', 'TConfigCompProps', CallMethod);
AddDefaultProperty('Components', 'Integer', 'TConfigCompProps', CallMethod);
end;

Script.AddObject('Components', FComponents);


and for the CallMethod I have the next :

if MethodName = 'COMPONENTS.GET' then Result := Integer(TConfigCompList(Instance).Components[Params[0]])
else if MethodName = 'COMPONENTS.SET' then TStrings(Instance).Objects[Params[0]] := TConfigCompList(Integer(Params[1]))
else if MethodName = 'STRINGS.GET' then Result := TStrings(Instance).Strings[Params[0]]
else if MethodName = 'STRINGS.SET' then TStrings(Instance).Strings[Params[0]] := Params[1];

The first Line is the important one.

I use the next SCRIPT :

begin
ResultValue := Components[0].CD_COLOR;
end.

but when interpret this script I get and exception: "Invalid Class typecast".

Any one can help me about how should I declare the CallMethod for gain access to the Properties of the TConfigCompProps class?

Thank you in advance!


Leave a Comment

Rich Text Editor. To edit a paragraph's style, hit tab to get to the paragraph menu. From there you will be able to pick one style. Nothing defaults to paragraph. An inline formatting menu will show up when you select text. Hit tab to get into that menu. Some elements, such as rich link embeds, images, loading indicators, and error messages may get inserted into the editor. You may navigate to these using the arrow keys inside of the editor and delete them with the delete or backspace key.