I searched in the documentation and leaned how to add a Class and that is good.
I continued my quest, then downloaded the XojoExample.zio archive and found tons of things. I stopped my quest when I realized that I forget what I was searching
Create a class. Add properties, methods, etc. Drag your class into a window or create an object in the code with Var xyz As New myClass and use it like any other class.
Or create a new class and enter an existing class as a super and extend this class with methods, constants, properties, etc. as you need them. Then you use this new class like any other.
You use the scope to control which methods, properties, etc. can be accessed via the class or which are only used internally within the class. As alwaysâŠ
Itâs not magic and once you get the hang of it, you wonât want to do without it. Your own classes are an essential part of object-oriented programming.
There are cases when you simply cannot do without. For example, the other day I needed to write an EditCopy handler for a ListBox that would copy its content as a JSON object. Only you cannot add a menu handler to a ListBox and if you add it to the window it wonât be invoked as the ListBox already handles the event and copies its content to the clipboard as text. The solution was to create a subclass of ListBox by dragging a ListBox to my project. To that subclass I could then add a menu handler for EditCopy. The nice thing was that once I had defined a custom ListBox I could insert these custom ListBoxes anywhere within my project (and I could also use it in other projects).
For complex data structures with components of different types, classes are often the best solution, rather than stuffing everything in a dictionary or JSON object. Itâs more efficient when you specify exactly what the components are by creating properties of a specific type, as opposed to using variants for everything. You will soon notice that many methods only deal with the components of some class and could thus be encapsulated as (possibly private) methods of the class rather than as methods of a window or module. Also constants and localized strings that are only relevant to a class should be local to that class. The resulting code is much neater, cleaner, and also easier to maintain and to re-use in other projects.
Iwill watch it (even if I have bad experience o video tutorials)âŠ
Example:
âTo open the SIM Card, insert the provided too intise the appropriate hole.â
Sorry guy, no tools, and⊠where is the appropriate hole ?
After sometimes I found an object I could use, and it takes times to find the correct pression to make it open !
Keep in mind that just by using Xojo, you are using classes. Every control and just about every âthingâ you use in a Xojo project is a class.
For instance, DesktopListBox is a class. The items that you place on a window are instances of a class. URLConnection is a class. So to say you have no experience is incorrect. You just havenât created your own yet, but if you think about how these other things work, it might help you understand how your own might too.
I have several classes that I use in listboxes. For a listbox row, there is a RowTag you can add. But suppose I need several items of information for that row. Then I make a class with several properties, one property for each item of data that the row need to store (perhaps needed by the Paint event). Then I do this:
Var ptr as MyClass
ptr = new MyClass
ptr.var1 = 27
ptr.var2 = 43
ptr.var3 = False
myListbox.RowTagAt (row) = ptr
And now the rowtag has three data items in it. Magic!
i think it depend on the project you are working on.
A class is quite similar to a module.
classes are useful to solve complex tasks.
or for separate data, example with a multiplayer game.
Players() As Player
Players.Add new Player("Player 1")
Players.Add new Player("Player 2")
but mostly to combine classes, to build a hierarchy.
the Players would be part of a Game class.
Player could have a list of cards and each is a Card class/object.
for each pl As Player in Players
pl.ProcessInput
next