I.T. Discussion Community!
-Collapse +Expand
Delphi
Search Delphi Group:

Advanced
-Collapse +Expand Delphi To/From
To/FromCODEGuides
-Collapse +Expand Delphi Store
PRESTWOODSTORE

Prestwood eMagazine

December Edition
Subscribe now! It's Free!
Enter your email:

   ► KBProgrammingDelphi for W...Delphi Downloads  Print This     
  From the July 2015 Issue of Prestwood eMag
 
Delphi for Win32:
Where Does Your Data Belong?
 
Posted 5 years ago on 6/10/2014
Take Away:

Back in the wild and wooly days of C/PM, DOS, and early versions of Windows, we programmers could store our data pretty much anywhere. It might not have been a good idea, but we could get away with it.

Things have changed drastically!!

If your program stores data, you need to know where it belongs, and that varies quite a bit from one version of Windows to others.

Read on to find out where your data belongs.

 A file from our File Library ► Delphi Downloads
 Tags: Data , Storage , Location

KB102504

Download Link:

 Download File Now

Back in the wild and wooly days of C/PM, DOS, and early versions of Windows, we programmers could store our data pretty much anywhere. It might not have been a good idea, but we could get away with it.

Things have changed drastically!!

If your program stores data, you need to know where it belongs, and that varies quite a bit from one version of Windows to others.

It's very common for applications to store data. It could be anything from a small INI file to a huge, local database. Often, a program needs to store quite a few kinds of data.

Windows now has rules about this. You may still be able to get away with ignoring these rules, but there can be consequences:

1: In a future version of Windows, your program may not run at all. It may not even run on contemporary operating systems that you didn't test.  You might write and test your program on Windows 7. Does that mean that it'll run properly on Windows server versions?

2: You might not even have to wait for a new version of Windows. A future Windows Update might patch the OS to fully enforce the data location rules.

3: Even if you get away with it forever, it could make you look like a dweeb. Instead of delivering a professional and workmanlike product, you could be seen as producing what you can get away with.

Unless you have a photographic memory, it probably won't be useful to try to remember all the rules because they change by OS. The rules for XP are different than for Windows 7, and those are different for Windows 8.

That means that, if you want to write a single version of your source code, a version that will run on all versions of Windows, it's best to ask Windows itself where it wants things stored.  Here is a list of constants offered by Windows. Pass them to the right constant, and Windows will return the fully qualified path for that constant.

CSIDL_DESKTOP
CSIDL_INTERNET
CSIDL_PROGRAMS
CSIDL_CONTROLS
CSIDL_PRINTERS
CSIDL_PERSONAL
CSIDL_FAVORITES
CSIDL_STARTUP
CSIDL_RECENT
CSIDL_SENDTO
CSIDL_BITBUCKET
CSIDL_STARTMENU
CSIDL_DESKTOPDIRECTORY
CSIDL_DRIVES
CSIDL_NETWORK
CSIDL_NETHOOD
CSIDL_FONTS
CSIDL_TEMPLATES
CSIDL_COMMON_STARTMENU
CSIDL_COMMON_PROGRAMS
CSIDL_COMMON_STARTUP
CSIDL_COMMON_DESKTOPDIRECTORY
CSIDL_APPDATA
CSIDL_PRINTHOOD
CSIDL_ALTSTARTUP
CSIDL_COMMON_ALTSTARTUP
CSIDL_COMMON_FAVORITES
CSIDL_INTERNET_CACHE
CSIDL_COOKIES
CSIDL_HISTORY

On this machine, for example (Windows 7 Ultimate), CSIDL_APPDATA means C:\Users\Wes\AppData\Roaming.

Delphi (and probably most other languages) has a function that, given one of the above constants, will return that path. It's in the ShFolder unit, and it's called SHGetFolderPath.  In the attached demo application, I've included a neat little wrapper for ShGetFolderPath that makes it a lot easier to use.

The attached project was written in Delphi 7 so as to be useful to as many people as possible. I've also tested if with later versions of Delphi because I use it in virtually every application I write.

Download Link:

 Download File Now


Comments

0 Comments.
Share a thought or comment...
 
Write a Comment...
...
Sign in...

If you are a member, Sign In. Or, you can Create a Free account now.


Anonymous Post (text-only, no HTML):

Enter your name and security key.

Your Name:
Security key = P1162A1
Enter key:
Article Contributed By Wes Peterson:

Wes Peterson is a Senior Programmer Analyst with Prestwood IT Solutions where he develops custom Windows software and custom websites using .Net and Delphi. When Wes is not coding for clients, he participates in this online community. Prior to his 10-year love-affair with Delphi, he worked with several other tools and databases. Currently he specializes in VS.Net using C# and VB.Net. To Wes, the .NET revolution is as exciting as the birth of Delphi.

Visit Profile

 KB Article #102504 Counter
5933
Since 6/10/2014

Follow PrestwoodBoards on: 


©1995-2019 PrestwoodBoards  [Security & Privacy]
Professional IT Services: Coding | Websites | Computer Tech