Android Question create a child sub into parent sab

ArminKH

Well-Known Member
hi
if you see Picasso lib we have so subs in this library
and one of this subs is "LoadFile" but on this sub we have too many other subs such as Fetch and...
B4X:
dim Picasso1 as Picasso
Picasso1.LoadFile.Fetch
now i want to create a library which that has child subs to one parent sub(Subs to Sub)
maybe my code can be similar to following codes
B4X:
Sub Result
    Sub male() As String
        Return "Male"
    End Sub
 
    Sub Female() As String
        Return "Female"
    End Sub
End Sub

Sub Activity_Create(FirstTime As Boolean)
    Dim A As MyLib
        Log(A.Result.male)
End Sub
how is possible same future on B4A??!!
thanx to all
 

ArminKH

Well-Known Member
Then I should read your question well :)
here is your code on that thread
On activity Main
B4X:
#Region  Project Attributes
    #ApplicationLabel: lm Create Library
    #VersionCode: 1
    #VersionName:
    'SupportedOrientations possible values: unspecified, landscape or portrait.
    #SupportedOrientations: unspecified
    #CanInstallToExternalStorage: False
#End Region

#Region  Activity Attributes
    #FullScreen: False
    #IncludeTitle: True
#End Region

Sub Process_Globals

End Sub

Sub Globals
  
End Sub

Sub Activity_Create(FirstTime As Boolean)

End Sub

Sub Activity_Resume
    Private ObjA As ClassA
    ObjA.Initialize
    ObjA.ShowSum
End Sub

Sub Activity_Pause (UserClosed As Boolean)

End Sub

and on ClassA
B4X:
'Class module
Sub Class_Globals
    Private ObjB As ClassB
End Sub

'Initializes the object. You can add parameters to this method if needed.
Public Sub Initialize
    ObjB.Initialize
End Sub

Public Sub ShowSum
    Msgbox(ObjB.Add(5,6),"")
End Sub

and on ClassB
B4X:
'Class module
Sub Class_Globals
  
End Sub

'Initializes the object. You can add parameters to this method if needed.
Public Sub Initialize

End Sub

Public Sub Add(Num1 As Int, Num2 As Int) As Int
    Return Num1 + Num2
End Sub
maybe if this sub
B4X:
Public Sub ShowSum
    Msgbox(ObjB.Add(5,6),"")
End Sub
can be changed to
B4X:
Public Sub ShowSum As ClassB

End Sub
then my problem solved
but i cant do this since last night to now :(

and excuse me if my BAD English makes misunderstanding :(
 
Upvote 0

ArminKH

Well-Known Member
ok after discussion about nose...please suggest a solution to solve my problem pleasezzzzzzzzzzzzzzzzzz :D
 
Upvote 0

LucaMs

Expert
Licensed User
Longtime User
ok after discussion about nose...please suggest a solution to solve my problem pleasezzzzzzzzzzzzzzzzzz :D



As mentioned, my English is poor (and at this time I do not understand even Italian :D).

I did not understand if you want help in creating classes or you need to know how to hide the properties and methods of the "service" class used by the main class.

In this second case, this was the Erel's answer and it works.
You will need to edit the XML for that. Remove ClassB from the XML.
 
Upvote 0

ArminKH

Well-Known Member
As mentioned, my English is poor (and at this time I do not understand even Italian :D).

I did not understand if you want help in creating classes or you need to know how to hide the properties and methods of the "service" class used by the main class.

In this second case, this was the Erel's answer and it works.
English : ok all of my problem is knowing how is possible following method on Picasso Lib

Italian : ok tutto il mio problema è sapere come sia possibile seguente metodo su Picasso Lib
B4X:
Dim Picasso1 As Picasso
        Picasso1.LoadFile.Fetch(Target1)
English :In this method we have a sub named ReadFile and another named Fetch
how is possible to implement this on b4a classes ? because i want to use this on my library

Italian:In questo metodo abbiamo un sub di nome ReadFile e un altro chiamato Trovalo
come sia possibile implementare questa sulle classi B4A? perché voglio utilizzare questo sul mio biblioteca

if still my question is Unclear then we can discuse with b4a Language :D
Thank u
 
Upvote 0

Cableguy

Expert
Licensed User
Longtime User
Well I'm playing around with this and I'm getting a strange error:

at anywheresoftware.b4a.shell.Shell.getCorrectClassName(Shell.java:522)

In my middle class where I define the second class
 
Upvote 0

ArminKH

Well-Known Member
Well I'm playing around with this and I'm getting a strange error:

at anywheresoftware.b4a.shell.Shell.getCorrectClassName(Shell.java:522)

In my middle class where I define the second class
Maybe @Erel can answer to this question because we can see similar subs on string builder which is a part of core library
 
Upvote 0

RandomCoder

Well-Known Member
Licensed User
Longtime User
Well this is the closest I have managed to achieve (see attached). I don't think you can do this without exposing the initialize method because when using a class you must initialise it first before being able to use it. Do you have to use Classes or could you use Code Modules? I've not tested whether it will work with code modules, I'm just guessing that you won't need to initialise first.

Main Activity...
B4X:
Sub Activity_Create(FirstTime As Boolean)
    'Do not forget to load the layout file created with the visual designer. For example:
    'Activity.LoadLayout("Layout1")
    Dim A As ClassA
    A.Initialize
    A.Result.Male
    A.Result.Female
End Sub

ClassA...
B4X:
'Class module
#IgnoreWarnings:12
Private Sub Class_Globals
End Sub

'Initializes the object. You can add parameters to this method if needed.
Public Sub Initialize
End Sub

Private Sub IsInitialized
End Sub

Public Sub Result As ClassB
    Dim B As ClassB
    B.Initialize
    Return B
End Sub

ClassB...
B4X:
'Class module
#IgnoreWarnings:12
Private Sub Class_Globals
End Sub

'Initializes the object. You can add parameters to this method if needed.
Public Sub Initialize
End Sub

Private Sub IsInitialized
End Sub

Public Sub Male
    Log("male")
End Sub

Public Sub Female
    Log("female")
End Sub
 

Attachments

  • ClassTest.zip
    6.8 KB · Views: 217
Upvote 0

ArminKH

Well-Known Member
Well this is the closest I have managed to achieve (see attached). I don't think you can do this without exposing the initialize method because when using a class you must initialise it first before being able to use it. Do you have to use Classes or could you use Code Modules? I've not tested whether it will work with code modules, I'm just guessing that you won't need to initialise first.

Main Activity...
B4X:
Sub Activity_Create(FirstTime As Boolean)
    'Do not forget to load the layout file created with the visual designer. For example:
    'Activity.LoadLayout("Layout1")
    Dim A As ClassA
    A.Initialize
    A.Result.Male
    A.Result.Female
End Sub

ClassA...
B4X:
'Class module
#IgnoreWarnings:12
Private Sub Class_Globals
End Sub

'Initializes the object. You can add parameters to this method if needed.
Public Sub Initialize
End Sub

Private Sub IsInitialized
End Sub

Public Sub Result As ClassB
    Dim B As ClassB
    B.Initialize
    Return B
End Sub

ClassB...
B4X:
'Class module
#IgnoreWarnings:12
Private Sub Class_Globals
End Sub

'Initializes the object. You can add parameters to this method if needed.
Public Sub Initialize
End Sub

Private Sub IsInitialized
End Sub

Public Sub Male
    Log("male")
End Sub

Public Sub Female
    Log("female")
End Sub
Thank u your attached source is exactly Something that i want to do
and now for next step thats can be better if we can Hide Initialize and IsInitialized And also ClassB From Activity and ClassB be Available just from ClassA
is this possible?
 
Upvote 0
Top