Real Software Forums

The forum for Real Studio and other Real Software products.
[ REAL Software Website | Board Index ]
It is currently Thu Sep 20, 2018 1:25 am
xojo

All times are UTC - 5 hours




Post new topic Reply to topic  [ 7 posts ] 
Author Message
 Post subject: instantiating a global object with custom class objects
PostPosted: Sat Jan 05, 2013 6:11 am 
Offline

Joined: Wed Sep 15, 2010 1:48 pm
Posts: 84
I am writing a little program to take my palm notes (1500 notes) into a real database. I have an object called palm_memo_db and that is a property as app.Palm_notes, as declared as Palm_notes() as palm_memo_db. I know I need to instantiating it, but I run into problems. Any help would be great.


I put palm_notes in a module, made sure it was global and in a bevelbutton I wrote:

if Palm_notes = nil then
Palm_notes as new palm_memo_db
end if


I get syntax error, other times I get this can not be used as a function, it is a class with properties, nothing else.

_________________
RS2012r2 Pro Win


Last edited by Dave_ on Wed Jan 09, 2013 1:06 pm, edited 4 times in total.

Top
 Profile  
Reply with quote  
 Post subject: Re: insubstantiating a global object... help!
PostPosted: Sat Jan 05, 2013 12:27 pm 
Offline
User avatar

Joined: Mon Feb 05, 2007 5:21 pm
Posts: 600
Location: New York, NY
Palm_notes = new palm_memo_db

"as" is only used when declaring a variable type.

_________________
Kem Tekinay
MacTechnologies Consulting
http://www.mactechnologies.com/

Need to develop, test, and refine regular expressions? Try RegExRX.


Top
 Profile  
Reply with quote  
 Post subject: Re: insubstantiating a global object... help!
PostPosted: Sat Jan 05, 2013 7:05 pm 
Offline

Joined: Wed Sep 15, 2010 1:48 pm
Posts: 84
Palm_notes(0) = new palm_memo_db


I had to change it to get it to work. That worked. Thanks!

Is it better to do this:

Palm_notes(0) = new palm_memo_db


or this:

Palm_notes(-1) = new palm_memo_db

_________________
RS2012r2 Pro Win


Top
 Profile  
Reply with quote  
 Post subject: Re: insubstantiating a global object.[solved]
PostPosted: Sat Jan 05, 2013 7:40 pm 
Offline

Joined: Fri Dec 01, 2006 3:09 pm
Posts: 650
Location: Tennessee, USA
Assuming Palm_notes is going to be an array of palm_memo_db objects then initially DIM Palm_notes as:
Palm_notes(-1) As palm_memo_db
That way at the start of execution you have an array with zero elements. Within whatever kind of loop that you have to fill the array you can use this to append another element to the array:
Palm_notes.append New palm_memo_db
The first time you do that you will have element 0 of the array. The next time element 1 and so on. After appending the new element you follow that statement up with the code to fill in the properties of the new object.

At any time you can find out the number of elements in the array by using the UBOUND function:
n = Ubound(Palm_notes)
where n is an integer. Your array elements will run from 0 to n. If, at any time, you wish to refill the array then you can use the command:
ReDim Palm_notes(-1)
to once again have an empty array and then go through whatever code to refill it with new data.


Top
 Profile  
Reply with quote  
 Post subject: Re: instantiating a global object with other objects inside
PostPosted: Wed Jan 09, 2013 7:24 am 
Offline

Joined: Wed Sep 15, 2010 1:48 pm
Posts: 84
Thanks for the clarification.

I added a date object to the palm_notes_db class, instantiating as palm_note (single record) and get a nil object error on the date object. I searched the forums, and found that I have to instantiating the date object (and from what i understand, any class object you create that is a property in another class), again the smart timhare said that you can do it two ways, in a constructor or test for nil after the parent object was instantiating.

In the constructor how do I instantiating a date object to an object hat holds a date object in properties?
in constructor do you just dim it? but DIM is only for local variables, and this is an object. ???

As instantiating as needed, this still does not work. I know i am not getting my syntax correct:
If palm_note.DateCreated = nil then
palm_note.DateCreated as date
palm_note = new date
palm_note.DateCreated.TotalSeconds = 0

else
palm_note.DateCreated.TotalSeconds = 0

end if


What I am asking, if I DIM palm_note as palm_memo_db, how do I instantiating a date object in palm_note?

_________________
RS2012r2 Pro Win


Last edited by Dave_ on Wed Jan 09, 2013 1:06 pm, edited 2 times in total.

Top
 Profile  
Reply with quote  
 Post subject: Re: insubstantiating a global object with custom class objec
PostPosted: Wed Jan 09, 2013 9:35 am 
Offline
User avatar

Joined: Sun Aug 05, 2007 10:46 am
Posts: 4931
Location: San Diego, CA
Put your date information in the CONSTRUCTOR of your palm_note class


and DateCreated must first be declared as a property of that class



and for future refrerence

Quote:
Creating an instance of a class is sometimes referred to as instantiating the class
'


not "insubstantiate"

_________________
Dave Sisemore
iMac I7[2012], OSX Mountain Lion 10.8.3 RB2012r2.1
Note : I am not interested in any solutions that involve custom Plug-ins of any kind


Top
 Profile  
Reply with quote  
 Post subject: Re: instantiating a global object with custom class objects
PostPosted: Wed Jan 09, 2013 1:13 pm 
Offline

Joined: Wed Sep 15, 2010 1:48 pm
Posts: 84
Thanks,

I guess I got my sub routines mixed up with instantiating.

In the constructor of the class I put one line of code, and that stopped the nil object exception for the date object as a property of the class:

// if you have an object you have to create a NEW reference to it to instantiate it if the object is in a class.

DateCreated = new date


datecreated is a date and is a property of a class

_________________
RS2012r2 Pro Win


Top
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 7 posts ] 

All times are UTC - 5 hours


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
Jump to:  
cron
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group