fuqr Messages: 16 Registered: July 2007 Location: Singapore
Promising Member
Hi,
In HomeBudget example, the DB data file is fixed & named as "HomeBudget.db3". How I can add an option or THISBACK(DbSaveAs) to save it as a db file which name can be assigned freely?
To make a SaveAs menu and save the DB with another name is easy.
Just add a menu to HomeBudgetLayout, connect it with SaveAs callback, which contain something like
FileSel fsel;
if(fsel.ExecuteSaveAs(t_("Save Database As...")))
{
if(FileExists(DB_file)) // DB_file is current DB name
{
if(FileCopy(DB_file, fsel.Get()))
DB_file = fsel.Get();
else
PromptOK("Error saving file!");
}
}
The hard (not so hard ) part is if you want to make HomeBudget to load last DB, because of it current implementation which create DB session in GUI_APP_MAIN. You can do what you want with current implementation but must do a lot of test to see if current DB exist, you may move the creation of hb instance(from main), up, before DB initialization to use HomeBudget Serialize and get last DB file name from configuration file.
Or you may remake some part of HomeBudget and move somehow the DB initialization in HomeBudget Setup.
There are others alternatives, Just try. Or if you are a newbie (like me) try simple things until have the knowledge to do advanced stuff.
fuqr Messages: 16 Registered: July 2007 Location: Singapore
Promising Member
Thanks bytefield,
You are right the problem is the DB session is created in GUI_APP_MAIN.
Acturaly what I tried is the following:(simple way )
===============================================
String filenameas; // I put in global variable: *.h
GUI_APP_MAIN
{
......
String filename = fs;
FileIn fi(filename);
filenameas = filename; // failed line ???
......
}
===================================================
To open different DB file I didn't use *.cfg file.
Thanks for your help!