Computer Science Canada Default value of type-report not possible? |
Author: | ModsCentral [ Thu Mar 29, 2012 4:53 pm ] | ||||
Post subject: | Default value of type-report not possible? | ||||
I am trying to finish off this TextArea module that I am having a great deal of success with, now I've run into 1 minor issue. Currently whoever uses my module can simply create a TextArea using the following
As you can see above, my issue is that the user must call "setDefault(nameOfField)" in order for this program to actually work. This is because I'm using a type - report as a collection for the properties, and so when the module goes to initiate the textarea using the properties, there is no default value. What I need is a way to simple set a default value to the type variables like so.
So, does anyone have any ideas on how I can go about this? Without having to create a procedure to call to set the default values (Currently what I'm doing) ALSO I am also trying to find a way to change the cursor to the text selection cursor for this module, as far I know there is no way to remove the cursor. I'm thinking of creating a set of vb programs to change the mouse cursor as a process, maybe that should do it. Thanks in advance |
Author: | Tony [ Thu Mar 29, 2012 5:02 pm ] |
Post subject: | RE:Default value of type-report not possible? |
if you make TextArea be a class instead of a record, then it can contain all the same fields + methods (procedures). Some of those methods (a constructor) will run by default, whenever a new instance (variable) is created, so it can set the defaults on its own. |
Author: | ModsCentral [ Thu Mar 29, 2012 5:07 pm ] |
Post subject: | Re: Default value of type-report not possible? |
How would I go about creating a procedure to run when a new variable of that type is instantiated? |
Author: | Tony [ Thu Mar 29, 2012 5:12 pm ] |
Post subject: | RE:Default value of type-report not possible? |
a constructor is automatically executed on creation. It can be used to trigger any other actions that need to take place. |
Author: | ModsCentral [ Thu Mar 29, 2012 5:25 pm ] |
Post subject: | Re: Default value of type-report not possible? |
My apologies but I'm still lost, how can I create a constructor? If I were to use this would it automatically call my procedure to set default values and create the filed as I want? |
Author: | Tony [ Thu Mar 29, 2012 5:31 pm ] |
Post subject: | RE:Default value of type-report not possible? |
see class and new |
Author: | ModsCentral [ Thu Mar 29, 2012 5:32 pm ] |
Post subject: | Re: Default value of type-report not possible? |
OK I'm trying to get my head wrapped around the differences between classes and modules. So if I use a class, and I create a textarea, should I use new, and if so will this then make the defined variables within the class unique to that specific variable? It's hard for me to explain this, but if this is the case then I can simply just remove type and have a list of variables with initial values without the type record, yes? |
Author: | ModsCentral [ Thu Mar 29, 2012 5:43 pm ] |
Post subject: | Re: Default value of type-report not possible? |
Ok basically what I'm doing is using a module, with a type within it, and in my main program, I'm creating a new variable of that datatype, however there is no default value, what would you suggest (Can you provide sample code?) |
Author: | Tony [ Thu Mar 29, 2012 5:53 pm ] |
Post subject: | RE:Default value of type-report not possible? |
I would suggest picking up some OOP concepts. http://en.wikipedia.org/wiki/Object-oriented_programming |
Author: | Raknarg [ Thu Mar 29, 2012 6:56 pm ] |
Post subject: | RE:Default value of type-report not possible? |
Well, I like to use this example for explaining the difference. Lets say you're going to make a module to control the movement of a character in an RPG. This would be good for a module, because you have a bunch of procedures and functions that relate to a general task, and it doesnt need to act differently upon different situations. Your character movement (in functionality) will never change. Classes, on the other hand, are fairly different because you are actually creating a new object with different properties, and it will act differently than other objects even if they are from the same class, because they will complete a different task. This is the reason you would not create a button module, because you want to create many buttons that do different things. Or, in your case, a text area that will act independantly from other text areas. Idk if that makes sense to you, but I think about it sort of that way. Generalization vs specific tasks. |
Author: | Raknarg [ Thu Mar 29, 2012 6:58 pm ] | ||||
Post subject: | RE:Default value of type-report not possible? | ||||
Tony, if you would like to chip in or completely negate my argument, that would be acceptable ![]() Also, I made a pretty weak example, but an example none the less
or, in your case:
|
Author: | ModsCentral [ Thu Mar 29, 2012 7:22 pm ] | ||||||
Post subject: | Re: Default value of type-report not possible? | ||||||
That's the example I was looking for, see my issue is I'm trying to relate the coding the user will use as close to actionscript 3 (flash) as possible hereby relating the properties to this.
Currently I have that with the following module
and the main program >>
This works so far, except I would like to just eliminate the whole create and setdefault functions to be called. Also I know processes are sort of deprecated but they run individually (Just having an issue with cancelling the cursor flash process) I'll give your code a shot, thanks ![]() |
Author: | ModsCentral [ Thu Mar 29, 2012 7:25 pm ] | ||
Post subject: | Re: Default value of type-report not possible? | ||
Also, is it possible to edit the variables outside the class? EDIT #1 Just realized Turing throws an error "... readonly" yet if you select run anyway, the variable is hereby modified. Weird? EDIT #2 So far what you have is what i need, except now I'm stuck with my alternate issue, trying to get the function create to get called automatically. Can I use forward's or something along with the procedure to call it within the class? EDIT #3
Is what I have now. I don't want to call the create function manually ;/ is that required? |
Author: | Raknarg [ Thu Mar 29, 2012 7:44 pm ] |
Post subject: | RE:Default value of type-report not possible? |
Yes, a class is not really a procedure. Something will have to be called for anything to work. Create, or initialize as I usually call it, will have to be called at the initial instance of the objects use. |
Author: | ModsCentral [ Thu Mar 29, 2012 7:54 pm ] |
Post subject: | Re: Default value of type-report not possible? |
Alright modified my code to work with classes. This definitely makes them 100% independent with all others objects which is nice, and also you won't need to pass in the object to initiate it. However, are you saying you must call for example > textfield -> load, in order for it to show any changes made to the properties? Is there no way for the class to detect any modifications to the variables hence call the load proc itself? Maybe a process by which checks each value with a temporarily saved value, and if different then reload? |
Author: | Tony [ Thu Mar 29, 2012 8:00 pm ] | ||||
Post subject: | Re: Default value of type-report not possible? | ||||
ModsCentral @ Thu Mar 29, 2012 7:54 pm wrote: Is there no way for the class to detect any modifications to the variables hence call the load proc itself?
This is typically accomplished by keeping the variables private, and exposing them through getter/setter methods. So instead of
you'd do
which would internally assign 42 to variable x, but could also do other actions. |