Real Software Forums

The forum for Real Studio and other Real Software products.
[ REAL Software Website | Board Index ]
It is currently Wed Apr 08, 2020 2:29 pm
xojo

All times are UTC - 5 hours




Post new topic Reply to topic  [ 3 posts ] 
Author Message
 Post subject: Opinions please re - handling dates and times - sub-classing
PostPosted: Thu May 09, 2013 10:37 pm 
Offline
User avatar

Joined: Sat Oct 01, 2005 4:47 am
Posts: 130
Location: Melbourne, Australia
I've subclassed a TextField, naming it "base_Field_Date". As you can gather, it will be this control that is plonked on windows to manipulate date & time stuff.

In this sub-class I've added an integer property "DateType" and have set up constants 1,2 & 3 representing the datetype, 1 = Date and Time, 2 = Date only and 3 = Time only. I've also created three purpose functions each returning a boolean value. The function names are, IsDateAndTime(), IsDateOnly() and IsTimeOnly(). These functions are utilised when looping controls on a window and for date controls the correct date/time data is assigned to the control (and read back into the database).

Using this approach I have to handle, outside of the class, constants representing the date type relevant to the sub-class. Not a huge problem. In the sub-class I've defaulted the date/time data to be date and time display, so in debugging it should be obvious if I've forgotten to set the setting.

Another approach that has crossed my mind and appears simpler in implementation. I'm thinking of creating three sub-classed controls each based on the date type (Date and Time, Date only and Time only). I can do away with the functions checking for the date type as it will be a given the date type due to the type of sub-classed control.

I'm in the process of converting an existing Access database where there are 100's of forms (windows). Most have date and time info, nearly all have audit type date/time stuff plus traditional date and time fields. So I want to deal with Date controls in the simplest way possible.

After opinions please, for instance, are there any better ways? I'm all ears.

ps. For purpose database fields, the above sub-classed controls (which ever way I go) are sub-classed further to account for database type stuff (Table & Field names).

_________________
Steve
rs2012 r2.1 Windows 7.


Last edited by superjacent on Fri May 10, 2013 7:48 am, edited 1 time in total.

Top
 Profile  
Reply with quote  
 Post subject: Re: Opinions please re - handling dates and times - sub-clas
PostPosted: Fri May 10, 2013 7:32 am 
Offline
Real Software Engineer

Joined: Tue Jul 14, 2009 4:33 pm
Posts: 146
Location: Raleigh, NC
Why not put the three Public constants right onto your class and refer to them thusly:

if base_Field_Date1.DateType = base_Field_Date.DateAndTime then....

You could still have the three functions IsDateAndTime(), IsDate() and isTime()

Also, if you haven't tried this, Right-click on your control in the project list and select .... In the list of properties click the checkbox next to the DateType property (to make it visible in the Window Editor) and then to the right, you can define an enumeration for the property. Right there you can put human readable labels for each of the three possible values. Once you've done that, drag an instance out to a window and you'll see that users will have a menu to select from.

_________________
Greg O'Lone
Software Engineer
Real Software


Top
 Profile  
Reply with quote  
 Post subject: Re: Opinions please re - handling dates and times - sub-clas
PostPosted: Fri May 10, 2013 8:27 am 
Offline
User avatar

Joined: Sat Oct 01, 2005 4:47 am
Posts: 130
Location: Melbourne, Australia
Thanks Greg, your suggestion makes sense.

Stretch wrote:
Also, if you haven't tried this, Right-click on your control in the project list and select .... In the list of properties click the checkbox next to the DateType property (to make it visible in the Window Editor) and then to the right, you can define an enumeration for the property. Right there you can put human readable labels for each of the three possible values. Once you've done that, drag an instance out to a window and you'll see that users will have a menu to select from.

I was aware of the property list behaviour but not familiar with the enumeration aspect. This will make things a little easier.

_________________
Steve
rs2012 r2.1 Windows 7.


Top
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 3 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:  
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group