Monday, October 21, 2019

Delphi Programming User and Application Data Storage

Delphi Programming User and Application Data Storage When you need to store some content related to your Delphi application on the users hard disk, you should take care of the support for state separation of user data, user settings, and computer settings. For example, The Application Data folder in Windows should be used to store application-specific documents such as INI files, application state, temp files or similar. You should never use hard-coded paths to specific locations, such as c:\Program Files, as this may not work on other versions of Windows because the location of folders and directories can change with different versions of Windows. The SHGetFolderPath Windows API Function The SHGetFolderPath is available in the SHFolder unit. SHGetFolderPath retrieves the full path of a known folder identified. Heres a custom wrapper function around the SHGetFolderPath API to help you get any of the standard folders for all or the currently logged Windows user. Heres an example of using the SHGetFolderPath function: Drop a TRadioButtonGroup (name: RadioGroup1) on a formDrop a TLabel (name: Label1) on a formAdd 5 items to the radio group:[Currenty User]\My DocumentsAll Users\Application Data[User Specific]\Application DataProgram FilesAll Users\DocumentsHandle the RadioGroups OnClick event as: Note: [Current User] is the name of the currently logged in Windows user. Note: The SHGetFolderPath is a superset of SHGetSpecialFolderPath. You should not store application-specific data (such as temporary files, user preferences, application configuration files, and so on) in the My Documents folder. Instead, use an application-specific file that is located in a valid Application Data folder. Always append a subfolder to the path that SHGetFolderPath returns. Use the following convention: \Application Data\Company Name\Product Name\Product Version.

No comments:

Post a Comment

Note: Only a member of this blog may post a comment.