SRL Archive - Reflection Help

Getting a 'sub-child' interface component in reflection


Cstrike

2010-10-10 10:51:09

Thanks to Pyroryan and others (you know who you are ;)) I now know interfaces :)!!

Though there's one thing with reflection that is missing with interfaces:
It can get ParentI and ChildI interfaces, for example:


Assuming I'm viewing this through an RSBot interface browser for simplicity
+ = what I can interact with (both in reflection and rsbot)
(-) = what I cannot get at (can *only* get data from rsbot, not reflection)

Interface 25 [COLOR="Green"]+[/COLOR]
Interface 143 [COLOR="Green"]+[/COLOR]
- Child Component 1 [COLOR="Green"]+[/COLOR]
- Child Component 2 [COLOR="Green"]+[/COLOR]
- Child Component 3 [COLOR="Green"]+[/COLOR]
- Child Component Folder 4 [COLOR="Green"]+[/COLOR] <-- I can get data on this, but I can't get data on components inside this component
- Sub-Child Component 1 [COLOR="Red"](-)[/COLOR]
- Sub-Child Component 2 [COLOR="Red"](-)[/COLOR] <-- I need to access this data but I can't
- Sub-Child Component 3 [COLOR="Red"](-)[/COLOR]
- Child Component 5 [COLOR="Green"]+[/COLOR]
Interface 164 [COLOR="Green"]+[/COLOR]
Interface 199 [COLOR="Green"]+[/COLOR]

For solving a random (yeah I was trying this last night), the data I need to solve the entire random flawlessly resides in that Sub-Child component, but it's technically the *third* index, whereas reflection code current only goes down to the second index. While this is pretty useful, is there a way I get get down there?
Does more code need to be added?
Thanks

ZephyrsFury

2010-10-10 11:35:13

You need to get the child of an interface child:


function GetComponentText(ParentI, ChildI, CompI: Integer): String;
var
Text, Child, Comp: Integer;
begin
Child := GetInterface(ParentI, ChildI);
Comp := SmartGetFieldArrayObject(Child, hook_interface_GetChildren, compI); //Getting the children components of the Child component
Text := SmartGetFieldObject(Comp, hook_interface_GetText);
Result := GetJavaString(Text, 255);
SmartFreeObject(Text);
SmartFreeObject(Comp);
SmartFreeObject(Child);
end;

Usage for your example above:

WriteLn(GetComponentText(143, 4, 2));