有关程序设置的保存,抱歉分不多。(10分)

  • 主题发起人 主题发起人 阿乐
  • 开始时间 开始时间

阿乐

Unregistered / Unconfirmed
GUEST, unregistred user!
我要在程序中进行对系统的一些设置<br>可是程序关闭后,设置就丢失了,我<br>怎样才能将设置保存下来,并在下次<br>使用程序时将设置调入?
 
记在注册表中
 
可以使用楼上说的,当然也可以使用Ini文件进行记录。然后在程序启动时从中取得上次<br>的保存信息就可以了。
 
具体如何在程序中添加代码实现?谢谢!
 
在关闭事件里保存设置,<br>在创建事件里读取设置。
 
还是写在ini文件中好
 
use 添加 Registry,<br>我程序中用到的,参考一下!<br>//读出<br>procedure TFrmBak.FormShow(Sender: TObject);<br>&nbsp; function GetBackPath: string;<br>&nbsp; var<br>&nbsp; &nbsp; Reg: TRegistry;<br>&nbsp; begin<br>&nbsp; &nbsp; Reg := Tregistry.Create;<br>&nbsp; &nbsp; try<br>&nbsp; &nbsp; &nbsp; Reg.RootKey := HKEY_CURRENT_USER;<br>&nbsp; &nbsp; &nbsp; if Reg.OpenKey('/Software/LdcErpAcc/LDCDataBase', False) then<br>&nbsp; &nbsp; &nbsp; &nbsp; Result := Reg.ReadString('BackPath');<br>&nbsp; &nbsp; finally<br>&nbsp; &nbsp; &nbsp; Reg.closekey;<br>&nbsp; &nbsp; &nbsp; Reg.Free;<br>&nbsp; &nbsp; end;<br>&nbsp; end;<br>begin<br>&nbsp; StrOldBackPath := GetBackPath + DataBaseFrm.strdata;<br>&nbsp; dxButtonEdit1.text := GetBackPath + DataBaseFrm.strdata + FormatDateTime('yyyymmdd', Now) + '.dat';<br>end;<br>//写入<br>procedure TFrmBak.FormClose(Sender: TObject; var Action: TCloseAction);<br>var<br>&nbsp; Reg: TRegistry;<br>&nbsp; StrBackPath: string;<br>&nbsp; i: integer;<br>begin<br>&nbsp; i := length(StrRScan(pchar(Trim(dxButtonEdit1.text)), '/'));<br>&nbsp; StrBackPath := Copy(Trim(dxButtonEdit1.text), 1, (length(Trim(dxButtonEdit1.text)) - i + 1));<br>&nbsp; if (Trim(StrOldBackPath) &lt;&gt; StrBackPath) and (BBack = True) then<br>&nbsp; begin<br>&nbsp; &nbsp; Reg := TRegistry.Create;<br>&nbsp; &nbsp; try<br>&nbsp; &nbsp; &nbsp; Reg.RootKey := HKEY_CURRENT_USER;<br>&nbsp; &nbsp; &nbsp; if Reg.OpenKey('/Software/LdcErpAcc/LDCDataBase', False) = False then<br>&nbsp; &nbsp; &nbsp; begin<br>&nbsp; &nbsp; &nbsp; //如果注册表中没有信息则创建信息<br>&nbsp; &nbsp; &nbsp; &nbsp; reg.CreateKey('/Software/LdcErpAcc/LDCDataBase');<br>&nbsp; &nbsp; &nbsp; &nbsp; Reg.OpenKey('/Software/LdcErpAcc/LDCDataBase', True);<br>&nbsp; &nbsp; &nbsp; &nbsp; Reg.WriteString('BackPath', StrBackPath);<br>&nbsp; &nbsp; &nbsp; end;<br>&nbsp; &nbsp; &nbsp; if Reg.OpenKey('/Software/LdcErpAcc/LDCDataBase', False) then<br>&nbsp; &nbsp; &nbsp; &nbsp; Reg.WriteString('BackPath', StrBackPath);<br>&nbsp; &nbsp; finally<br>&nbsp; &nbsp; &nbsp; Reg.closekey;<br>&nbsp; &nbsp; &nbsp; Reg.free;<br>&nbsp; &nbsp; end;<br>&nbsp; end;<br>end;<br>
 
china_peng讲的很详细,只好给他加分了。<br>不过相信其他朋友的方法应当是同样有效的<br>谢谢大家的指点!
 
后退
顶部