将用户和Delphi应用程序数据存储在正确的位置

When you need to store some content related to your Delphi application on the user's hard disk, you should take care of the support for state separation of user data, user settings, and computer settings.

当需要在用户的硬盘上存储与Delphi应用程序相关的某些内容时,应注意支持用户数据,用户设置和计算机设置的状态分离。

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.

例如, Windows中的“应用程序数据”文件夹应用于存储特定于应用程序的文档,例如INI文件 ,应用程序状态,临时文件或类似文件。

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.

绝对不要使用指向特定位置的硬编码路径,例如“ c:\ Program Files”,因为在其他版本的Windows上这可能不起作用,因为文件夹和目录的位置会随Windows的不同版本而改变。

SHGetFolderPath Windows API函数 ( The SHGetFolderPath Windows API Function )

The SHGetFolderPath is available in the SHFolder unit. SHGetFolderPath retrieves the full path of a known folder identified.

SHGetFolderPath在SHFolder单元中可用。 SHGetFolderPath检索标识的已知文件夹的完整路径。

Here's 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.

这是一个围绕SHGetFolderPath API的自定义包装函数,可帮助您获取所有或当前登录的Windows用户的任何标准文件夹。

Here's an example of using the SHGetFolderPath function:

这是使用SHGetFolderPath函数的示例:

  • Drop a TRadioButtonGroup (name: "RadioGroup1") on a form

    将一个TRadioButtonGroup(名称:“ RadioGroup1”)放到窗体上
  • Drop a TLabel (name: "Label1") on a form

    将TLabel(名称:“ Label1”)放在表单上
  • Add 5 items to the radio group:

    将5个项目添加到广播组:

    • "[Currenty User]\My Documents"

      “ [当前用户] \我的文档”
    • "All Users\Application Data"

      “所有用户\应用程序数据”
    • "[User Specific]\Application Data"

      “ [用户特定] \应用程序数据”
    • "Program Files"

      “程序文件”
    • "All Users\Documents"

      “所有用户\文档”
  • Handle the RadioGroup's OnClick event as:

    将RadioGroup的OnClick事件处理为:

Note: "[Current User]" is the name of the currently logged in Windows user.

注意:“ [当前用户]”是当前登录的Windows用户的名称。

Note: The SHGetFolderPath is a superset of SHGetSpecialFolderPath.

注意:SHGetFolderPath是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".

始终将子文件夹附加到SHGetFolderPath返回的路径。 使用以下约定:“ \应用程序数据\公司名称\产品名称\产品版本”。

翻译自: https://www.thoughtco.com/store-user-and-application-data-in-the-correct-location-1058164

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值