I feel like I’m at a point in my app where things are going pretty well, but the potential to go seriously wrong is looming, and I want to make sure there isn’t a better way to do this before I have to go back and fix everything.
Right now I have a table in my database named “Settings” where I save user settings.
When the user logs in I pull their Settings out of the table based on the UserID, load them into a set of Session properties so I can access them anywhere, and then put them into a Settings page where they can be updated if the user needs to do so.
It works fine.
The issue is (and maybe it isn’t an issue) the number of Session properties is getting pretty big, and I feel like I should separate them out somehow. My first thought is to add a class (Named Settings, I suppose) and add the properties to that, and then call them from that class. Would that be the way to go? Is there a better way to do this?
Thank you!
For desktop projects I do my dB table lookup by userId and then I create a sessionUserProfile class (like you mentioned above). I then stash this class on a module for easy in session access. I then discard this class when the user logs off.
This gives me the flexibility to add potential methods and any property I want in the confines of one class vs mixing these profile properties in with other session properties in your case.
HTH
Mike
you could copy your settings table into an in-memory sqlite and use that one for the user to make changes. Once the user is done, you can write the changes back to your main database.
I’d vote for turning the settings into a class. The class could be able to read and write the settings per user too. My app ARGen can help turn databases into Xojo classes like this
The code advantage of this is that your settings can autocomplete. You could write code like:
if Session.oUserSettings.bLikesCode then
// Do stuff because the user likes code
end
1 Like
All good food for thought. It’s good to know I’m not COMPLETELY out in left field with what I was doing. Thank you!
2 Likes