What happened to the Messenger Plus! forums on msghelp.net?
Shoutbox » MsgHelp Archive » Skype & Technology » Tech Talk » Saveing in C++

Pages: (2): « First [ 1 ] 2 » Last »
Saveing in C++
Author: Message:
DJeX
Veteran Member
*****

Avatar


Posts: 1138
Reputation: 11
– / Male / –
Joined: Jul 2003
O.P. Undecided  Saveing in C++
How would I save everything in my program the way it is and the next time I open my program every thing is back the same.
[Image: top.gif]
01-02-2005 09:34 PM
Profile PM Web Find Quote Report
RaceProUK
Elite Member
*****

Avatar

Posts: 6073
Reputation: 57
39 / Male / Flag
Joined: Oct 2003
RE: Saveing in C++
I recommend you look at the Registry API. By creating your own set of keys and values, you can store all your program's settings in one place. It's quite easy to do actually, just be careful of datatypes.

This post was edited on 01-03-2005 at 04:47 AM by WDZ.
[Image: spartaafk.png]
01-02-2005 10:18 PM
Profile PM Web Find Quote Report
DJeX
Veteran Member
*****

Avatar


Posts: 1138
Reputation: 11
– / Male / –
Joined: Jul 2003
O.P. RE: Saveing in C++
raceprouk,

I thought of that idea. But I have to much to save to the registry. I need to save it to a file.

Any one have any ideas?
[Image: top.gif]
01-02-2005 10:59 PM
Profile PM Web Find Quote Report
Choli
Elite Member
*****

Avatar
Choli

Posts: 4714
Reputation: 42
42 / Male / Flag
Joined: Jan 2003
RE: Saveing in C++
make each class dump all its variables (attributes) to a file (only one file, or one file per class) and next time, create the classes and make them read from the file in the same order you wrote to the file. That's the easyest way (for large amount of data). There are more complex ways to do the same, but all of them rely on the idea of having a file where you store all the info that defines the current status of your program.
Messenger Plus! en español:
<< http://www.msgpluslive.es/ >>
<< http://foro.msgpluslive.es/ >>
:plus4:
01-02-2005 11:08 PM
Profile PM Find Quote Report
DJeX
Veteran Member
*****

Avatar


Posts: 1138
Reputation: 11
– / Male / –
Joined: Jul 2003
O.P. RE: Saveing in C++
Sorry Choli, I'm just starting out with C++. How would I dump the class attributes to a file?
[Image: top.gif]
01-03-2005 01:58 AM
Profile PM Web Find Quote Report
CookieRevised
Elite Member
*****

Avatar

Posts: 15519
Reputation: 173
– / Male / Flag
Joined: Jul 2003
Status: Away
RE: Saveing in C++
To store data there are roughly two methods.

One method is to use the registry:
Benefits:
  + no extra file needed
Disadvantages:
  + Can't be easy exported/imported or changed by newbies
  + There are certain (unwritten) rules you must follow; you can't go storing data for your application wherever you like.
  + More and more the registry will get messed up with leftovers from bad written programs (also, the bigger the registry, the slower your PC will start up!)

Another method is to use a file:
Benefits:
  + You can write your own data storage format as you like (binary/textual/whatever).
  + You could use the known INI format to store data
  + Easy exported/imported/changed
  + The user can be certain that whenever he moves/deletes the application, all data and files are moved/deleted with it
Disadvantages:
  + an extra file could be needed (the file to store the data in)*

If you want to stick to an INI-file:
http://www.functionx.com/bcb/howto/inifile.htm
http://www.codeguru.com/Cpp/W-P/files/inifiles/article.php/c4455/

Although many people could say INI-files is something from the past, they are still much prefered and used by many others because of their easyness to create and handle (both by the programmer as by the user); you _know_ what the application changes, etc... Personally I also hate it when I'm never certain of what an application stores/changes what and where in the registry (Also, often things get left in the registry because of errors, etc. making it one big mess).

* PS: why I said "could be needed"? Because you could write a storage system where the actual exe-file is used as a storage file (eg: resources or other data added to the actual file). Of course in that case, the easnyess of using an extra textbased file will be gone.

This post was edited on 01-03-2005 at 03:03 AM by CookieRevised.
.-= A 'frrrrrrrituurrr' for Wacky =-.
01-03-2005 02:58 AM
Profile PM Find Quote Report
Choli
Elite Member
*****

Avatar
Choli

Posts: 4714
Reputation: 42
42 / Male / Flag
Joined: Jan 2003
RE: Saveing in C++
quote:
Originally posted by DJeX
Sorry Choli, I'm just starting out with C++. How would I dump the class attributes to a file?
the basic idea is that you create a metod that when called if saves all the variables to the file and another one for reading the file and setting the variables with the proper value. If you're new with C/C++, you should get used to manage files (open, close, read, write, .... them).

IMO, you have to ask yourself several questions: do you really want to save the exact status of your program or you only want to save the user settings? Think a bit about that, it's not the same and probably you do not want the first thing * (which is like pausing the execution of the program and resuming it later; quite complex because it envolves more things than just saving and loading all the status and settings)

As a summary of what Cookie said, and saying like a "geleral rule", you should use the registry to store the user settings of the program, ie: how the program behaves; and save into a file (or files) the data that the program manages: what the programs works with (user's data, documments, etc...).


*-> in case you want to save the whole status of your program: ask yourself: what differences the program in two instants of time? what may change from one moment to the next one? All that has to be measured and forms the status of the program. If you dessign the program well, all that will be in (and will be formed by) all the variables and classes of your program together with the current task that the program is doing, which should be doing nothing, because at the point where you save the status your program shouldn't be doing anything else.

--------

I know all this may seem quite complex to understand, because you're new at c++. Don't worry. First of all get used to the language and then start doing more complex things.

Let me suggest you a book: "Thinking in C++". It's a book made of 2 volumes and you can freely download from the internet (google it). I haven't read the whole book, but it seems a quite good book.
Messenger Plus! en español:
<< http://www.msgpluslive.es/ >>
<< http://foro.msgpluslive.es/ >>
:plus4:
01-03-2005 08:51 PM
Profile PM Find Quote Report
DJeX
Veteran Member
*****

Avatar


Posts: 1138
Reputation: 11
– / Male / –
Joined: Jul 2003
O.P. Grin  RE: Saveing in C++
Thanks for your replies. I'll take a look at the sites that Cookie posted when I get a chance.
 
For what Choil said, I really think I would want to save my programs settings to an ini file because I have tones of controls that need to be saved.

For example: What my program does is it highlights the editbox with the number you specify.

Here’s a picture so you can see what I’m talking about (so I don't sound crazy):

[Image: programss.JPG]

Now I want to save the name's the user types in, the numbers in the edit boxes, the color of the edit boxes, the money amount at the top and the starting date at the top. Then also have it reload the exact same way through the settings file I saved all of it to.

Now I know using 160 editboxs and about 20 static text boxes to make up a pretty good chart (I have to say) is stupid, but you have to give me credit for thinking of a way that I knew how to do it (Y)

With that said you should see why I would prefer the ini file better than the registry. :)

*DJeX readys up for the many sugestions and surprised remarks for his dodgy coding lol*

OH and the best part is the program works! (Y):D


I attached it if anyone wants to give it a try. Thanks.

.exe File Attachment: program.exe (670.5 KB)
This file has been downloaded 102 time(s).
[Image: top.gif]
01-03-2005 09:37 PM
Profile PM Web Find Quote Report
TheBlasphemer
Senior Member
****

Avatar

Posts: 714
Reputation: 47
36 / – / –
Joined: Mar 2004
RE: Saveing in C++
Look up the functions:
fwrite, fopen, fread,fclose, and if you find em try to find a list of related functions.

If you're going Windows only, look at CreateFile, CloseHandle, WriteFile, ReadFile :)

Hope that helps,

bye, TB
[Image: theblasp.png]
01-03-2005 09:51 PM
Profile PM Find Quote Report
DJeX
Veteran Member
*****

Avatar


Posts: 1138
Reputation: 11
– / Male / –
Joined: Jul 2003
O.P. RE: Saveing in C++
The website CookieRevised posted (http://www.functionx.com/bcb/howto/inifile.htm)

Was just what I was looking for. I can get it to save everyting except the color of the edit boxes.

Cookie would you know how?


This is how I write to the ini:

code:
StartUp->WriteString("CtlValues",  "txtPreview",   Edit1->Text);

^ That writes Edit1's text to ini.

I tryed:

code:
StartUp->WriteString("CtlValues",  "txtColor",   Edit1->Color;

^ But it don't write the color of the box it writes a number like -256438

This post was edited on 01-03-2005 at 10:27 PM by DJeX.
[Image: top.gif]
01-03-2005 10:26 PM
Profile PM Web Find Quote Report
Pages: (2): « First [ 1 ] 2 » Last »
« Next Oldest Return to Top Next Newest »


Threaded Mode | Linear Mode
View a Printable Version
Send this Thread to a Friend
Subscribe | Add to Favorites
Rate This Thread:

Forum Jump:

Forum Rules:
You cannot post new threads
You cannot post replies
You cannot post attachments
You can edit your posts
HTML is Off
myCode is On
Smilies are On
[img] Code is On