New to Xojo and OOP altogether. I create window1 and drag a button onto it. Then need to insert action. Now here’s where I get a bit confused. If after the user clicks the button, there is a lot of processing and number crunching that needs to be done, do I do all that coding right there in the action space? Also a bit confused how to know when and eventhandler needs to be inserted. I have gone through the books, but still not clear with me.
You could if you wished. Or add a new method - say MyCruncher. Put the code in there to do the number crunching, and in the pushbutton action just enter “MyCruncher” ( no quotes ). Then, later, if you wish to create a menu item for example, you just put “MyCruncher” in the menu handler. That way you don’t have to repeat the same code, which could lead to problems if you change one copy of the code but forget to change the other.
There are more complex things like threads, but maybe worry about that alternative another time.
my opinion… keep the EVENT and the PROCESSING apart…
create a METHOD that does the processing, and have the Button Action event call that method
This keeps a separation between the GUI and “business rules” and allows the “method” to be reused, and/or called by other parts of the program if required.
+10 to what Dave said. At first it seems to simple to put the processing in the events, but when you starting changing your UI around and/or have other ways of calling the “number crunching” you will want it separate.
Thank you guys very much.
If there’s a lot of time taken to do that number crunching you might want to use a thread to keep the UI active.
[quote=185993:@milford walton]Also a bit confused how to know when and eventhandler needs to be inserted. I have gone through the books, but still not clear with me.
In the old RealBASIC IDE all possible events for a control were shown in the IDE, and you just clicked on whichever you needed and added code. In the new IDE you have to “add” the events you want, and the possibilities for that control are shown when you ask to do so. If you need the event, just add it.
For silly example, say you wanted a control to be available only in the afternoon, you could add an open event, check the time in that event, and set the control to enabled or not. ( You could also do that elsewhere, such as the window open event, but this is just a silly example ).
I have about 60 hours of training video (200+ individual videos) for subscribers at http://xojo.bkeeney.com/XojoTraining/ when I go through a lot different classes and how I go about doing projects (been doing Xojo consulting for about 15 years now). I have 3 complete start to finish projects (2 desktop and 1 web app). Video training isn’t for everyone but if that’s something you like I’ve received lots of good feedback from people new to Real Studio and Xojo.
I have been using Xojo for a while now and I still pick up new things watching Bob’s videos.
First, welcome aboard Milford!
2nd: As Dave mentioned keep your code structured, create methods and functions. Do not repeat yourself in writing same code over and over again. Regardless of programming language there are some certain programming styles (n-tier architecture, Model-View-Controller etc.) which all tries to give structure, so that you always keep an overview when your projects becoming bigger and more complex.
Give a try with Brad Rhyne’s book “Introduction in programming with Xojo” its free as PDF on xojo’s website and in iBook Store.
Thank you guys so much. I have been looking at different languages and going back and forth. Still haven’t made up my mind. I will take a look Bob.
I took a look and the version of Xojo that is being explained is from 2013. And there quite a few videos that are for Real Basic. So haven’t gotten much help there. I am disabled and on a very limited budget so paying for intruction is just not possible for me.
Thanks Wayne. I am watchng every video on it i can find.
Also, feel free to ask questions as someone will probably have an answer for you…