Class caller

JesseW

Active Member
Licensed User
Longtime User
How do I determine which activity or class object has initialized and is using a class I am writing, so I can properly populate the Component argument of the CallSub statement for Event processing? I hate to just blindly set it to Main...

Many thanks in advance...
 
Create an object parameter in the class initialization sub and store it as a global variable (named something like Component). Pass 'Me' from the calling activity. Then use callsub (Component,"subName")
 
Last edited:
Upvote 0
Create an object parameter in the class initialization sub and store it as a global variable (named something like Component). Pass 'Me' from the calling activity. Then use callsub (Component,"subName")

I thought of that, but I'm creating a wrapper for the IME library, and want it to be a DIRECT replacement for it (adding only a few new properties), and IME.Initialize doesn't have a component sent, so my wrapper class cannot either.

I thought about trying something along the lines of a GetContext method of a Reflector object to get it, but I don't know Java at all... :(
 
Upvote 0
I wasn't really expecting it to work, but it looks as though you can save it in a random access file in your activity:

Code: Copy
   Dim R As RandomAccessFile
   R.Initialize(File.DirDefaultExternal,"Me.RAF",False)
   R.WriteObject(Me,True,0)
   R.Close

Then read it in your class.

Code: Copy
'Class module
Sub Class_Globals
   Dim Component As Object
End Sub

'Initializes the object. You can add parameters to this method if needed.
Public Sub Initialize
   
   Dim R As RandomAccessFile
   R.Initialize(File.DirDefaultExternal,"Me.RAF",False)
   Component = R.ReadObject(0)
   R.Close
   Log("Me2 "&Component)

End Sub

Sub DoSub
   CallSub(Component,"testsub")
End Sub

If your expecting multiple instances of the class, you'll have to do something with filenames, but it'll work for a single instance (or one at a time) class.
 
Last edited:
Upvote 0
Even if it does work, I need a way to INTERNALLY, within the class itself, know the component. the IME library knows it, so I'm assuming my wrapper class xIME should be able to find it somehow. It is my intent to provide this class that a programmer can simply replace their IME library with without breaking any code

instead of
Code: Copy
Dim IME as IME

they would replace as
Code: Copy
Dim IME as xIME

and their existing code would still work, but add three new properties, Height, Visible and HardwareKeyboard. For now, I'm just inserting Main as the component. I figure Erel, Andrew or Klaus may now. At least I hope someone does :)

thanks for your thoughts, Steve
 
Upvote 0
Actually...

I think it'd be a fantastic idea if Erel updated his IME library to include the three new properties

>HINT< >HINT<

:sign0162:
 
Upvote 0
no, just a b4a solution. it can encapsulate a java solution, but in b4a code. But I have another issue with the IME library that must be addressed before I can continue
 
Upvote 0
Try this, it seems to work on testing from different activities calling a class containing this code:

Code: Copy
Dim R As Reflector
R.Target=R.GetActivity
Component=R.RunMethod("getClass")
 
Upvote 0
Thanks Erel,

JesseW is trying to implement a direct drop in replacement for the IME library and didn't want to pass any additional parameters.
 
Upvote 0
yes, this is correct. since IME has no TargetObject parameter in its Initialize method, I don't want one in the extended ime class either. I want it to be a direct in-code replacement.

is there no way to determine the calling object? - thanks
 
Upvote 0
I see. However I think that this is the only solution that will work in all cases.

so in the case of native views and their events, as well as other b4a java libraries with events such as the IME library, the mechanism for resolving the calling object is not available in b4a?
 
Upvote 0
thank you Erel. I will change to that syntax.

1) am I correct in assuming whether in an activity, class or service I can use the new Me keyword when calling the .Initialize(Me, "EventName"), but not in a static code module?

2) is that a limitation of the Me keyword, or of the static code module?
 
Upvote 0
Back
Top