Hi all,
in my project I've 2 classes I wrote. These classes are substantilally viewers tha show a scrollable Canvas inside a big ScrollView2D panel (many thanks to @Informatix for his good ScrollView2D library). This way I've a big 2D scrollable canvas. It is used to simulate a 3D Printer or CNC machine.
Both classes have same methods with same arguments, the only difference of both classes are that the first one show a 2D view, the second one show a static 3D view I've created on a canvas using math calculations.
In my project currently I can switch from 2D view and 3D view just by declaring the right class I want as global variable (in Globals sub) this way:
This works, but now I want to add in the app settings the ability to switch from 2D to 3D view, so can be selected from end user, then when app restarts, it read from settings what view to use and use it.
What I need is the ability to declare a right class at runtime, but it need to be globally scoped because the app use it in many functions. Something like this:
I've even tried to manage both classes as Object but without success.
Is that possible? If yes, what is the best approach to do it?
Many thanks
in my project I've 2 classes I wrote. These classes are substantilally viewers tha show a scrollable Canvas inside a big ScrollView2D panel (many thanks to @Informatix for his good ScrollView2D library). This way I've a big 2D scrollable canvas. It is used to simulate a 3D Printer or CNC machine.
Both classes have same methods with same arguments, the only difference of both classes are that the first one show a 2D view, the second one show a static 3D view I've created on a canvas using math calculations.
In my project currently I can switch from 2D view and 3D view just by declaring the right class I want as global variable (in Globals sub) this way:
B4X:
' Uncomment just one
'Private Viewer As GCodeViewer2D
Private Viewer As GCodeViewer3D
This works, but now I want to add in the app settings the ability to switch from 2D to 3D view, so can be selected from end user, then when app restarts, it read from settings what view to use and use it.
What I need is the ability to declare a right class at runtime, but it need to be globally scoped because the app use it in many functions. Something like this:
B4X:
If Settings.UseViewer2D Then
Dim Viewer As GCodeViewer2D ' Must be a global variable
Else If Settings.UseViewer3D Then
Dim Viewer As GCodeViewer3D ' Must be a global variable
End If
......
' Use the right viewer class 2D or 3D
' NOTE: both classes have same methods and any sub the same arguments
Viewer.Initialize(pnlViewer, 1.0, Settings.Antialiasing)
Viewer.Show(5dip, 5dip, 60%x, 70.7%y)
Viewer.SetDrawingPlaneSize(Settings.X_MAX_POS, Settings.Y_MAX_POS) ' Setup drawing plane for a machine.
' Viewer.Resize(5dip, 5dip, 60%x, 70.7%y) ' Resize the viewer pamel
If Not (Settings.RoundPlane) Then
Viewer.setStartPoint(0, 0, 0) ' Set start point to X0 Y0 Z0
Log("Viewer StartPoint: 0,0,0")
Else
Viewer.setStartPoint(Settings.X_MAX_POS*0.5, Settings.Y_MAX_POS*0.5, 0) ' Set start point to X0 Y0 Z0
Log("Viewer StartPoint: " & (Settings.X_MAX_POS*0.5) & "," & (Settings.Y_MAX_POS*0.5) & ", 0")
End If
......
I've even tried to manage both classes as Object but without success.
Is that possible? If yes, what is the best approach to do it?
Many thanks
Last edited: