aaronk Well-Known Member Licensed User Longtime User Aug 5, 2014 #1 Hi, Just wondering how I can initialize a class during runtime? I have created a class and I have used it in a service, but during runtime I want to be able to initialize it many times. I know how to initialize it (MyClass.initialize) but can't work out how to initialize it multiple times. For example: When I open the app I want to press a button and it will initialize the class. eg. MyClass.initialize("test1") I then want to press the same button again, but initialize it with a different string eg. MyClass.initialize("test2") I want to be able to initialize the class multiple times without closing the previous one. I am guessing I need to Dim it in the Process_Globals ad then initialize it in Service_Create but can't work out how to do it multiple times during runtime. Anyone able to help me out ?
Hi, Just wondering how I can initialize a class during runtime? I have created a class and I have used it in a service, but during runtime I want to be able to initialize it many times. I know how to initialize it (MyClass.initialize) but can't work out how to initialize it multiple times. For example: When I open the app I want to press a button and it will initialize the class. eg. MyClass.initialize("test1") I then want to press the same button again, but initialize it with a different string eg. MyClass.initialize("test2") I want to be able to initialize the class multiple times without closing the previous one. I am guessing I need to Dim it in the Process_Globals ad then initialize it in Service_Create but can't work out how to do it multiple times during runtime. Anyone able to help me out ?
Erel B4X founder Staff member Licensed User Longtime User Aug 5, 2014 #2 Do you want to create multiple instances of this class? If yes then you need to call Dim varName As YourClass and then initialize the new object. Upvote 0
Do you want to create multiple instances of this class? If yes then you need to call Dim varName As YourClass and then initialize the new object.
LucaMs Expert Licensed User Longtime User Aug 5, 2014 #3 What is the purpose? You certainly know that you can have x number of instances of that class, different objects. Otherwise, "test1" or "test2" can be held in a simple property. Upvote 0
What is the purpose? You certainly know that you can have x number of instances of that class, different objects. Otherwise, "test1" or "test2" can be held in a simple property.
klaus Expert Licensed User Longtime User Aug 5, 2014 #4 Code: Copy Dim MyClass1, MyClass2, MyClass3 As MyClass ' ' MyClass1.Initialite("table1") ' MyClass2.Initialite("table2") ' MyClass3.Initialite("table3") Upvote 0
Code: Copy Dim MyClass1, MyClass2, MyClass3 As MyClass ' ' MyClass1.Initialite("table1") ' MyClass2.Initialite("table2") ' MyClass3.Initialite("table3")
LucaMs Expert Licensed User Longtime User Aug 5, 2014 #5 aaronk is and old and expert member. I think I misunderstood the question, that it is not so simple. Upvote 0
aaronk Well-Known Member Licensed User Longtime User Aug 5, 2014 #6 Erel said: Do you want to create multiple instances of this class? If yes then you need to call Dim varName As YourClass and then initialize the new object. Click to expand... Just like what Klaus suggested? If so, that will be pain as I wanted to keep pressing a button to add them without having to dim each of them since I might not know how many there are going to be. Would you say something like this will work? Code: Copy Dim MyNewClass(1000) As MyClass MyNewClass(1).Initialite("table1") Then each time I press a button add one: MyNewClass(2).Initialite("table2) Upvote 0
Erel said: Do you want to create multiple instances of this class? If yes then you need to call Dim varName As YourClass and then initialize the new object. Click to expand... Just like what Klaus suggested? If so, that will be pain as I wanted to keep pressing a button to add them without having to dim each of them since I might not know how many there are going to be. Would you say something like this will work? Code: Copy Dim MyNewClass(1000) As MyClass MyNewClass(1).Initialite("table1") Then each time I press a button add one: MyNewClass(2).Initialite("table2)
LucaMs Expert Licensed User Longtime User Aug 5, 2014 #7 You can use your Class like any other object! So you can also use a List or Map Upvote 0
klaus Expert Licensed User Longtime User Aug 5, 2014 #8 Depending on what your class is doing, you could also add a Tag property to your class. And Code: Copy Dim mc As MyClass mc.Initialite("table1") mc.Tag = 1 In in event routines use Sender like with all other views. Upvote 0
Depending on what your class is doing, you could also add a Tag property to your class. And Code: Copy Dim mc As MyClass mc.Initialite("table1") mc.Tag = 1 In in event routines use Sender like with all other views.