DELPHI中也有静态变量,但实现不了你的功能,因为程序一退出就全完了,只能把你要
保存的数据保存在数据库,文件或注册表中
保存在注册表的例子:
function LoadSetting:boolean;
//从注册表读取保存的设置
var
Reg: TRegistry;
begin
Reg := TRegistry.Create;
try
with Reg do
begin
RootKey:=HKEY_LOCAL_MACHINE;
if OpenKey(SREGSubKey+SAppName,True) then
begin
if ValueExists(SREGbSaveUserName) then
bSaveUserName := ReadBool (SREGbSaveUserName);
if ValueExists(SREGbUseFlatHint) then
bUseFlatHint := ReadBool (SREGbUseFlatHint);
if ValueExists(SREGbUseHint) then
bUseHint := ReadBool (SREGbUseHint);
if ValueExists(SREGbUseXPMenu) then
bUseXPMenu := ReadBool (SREGbUseXPMenu);
if ValueExists(SREGclBackColor) then
clBackColor := ReadInteger(SREGclBackColor);
if ValueExists(SREGiDrawStyle) then
iDrawStyle := ReadInteger(SREGiDrawStyle);
if ValueExists(SREGiDropDownCount) then
iDropDownCount := ReadInteger(SREGiDropDownCount);
if ValueExists(SREGsBackImage) then
sBackImage := ReadString (SREGsBackImage);
if ValueExists(SREGsDataBaseName) then
sDataBaseName := ReadString (SREGsDataBaseName);
if ValueExists(SREGsUserName) then
sUserName := ReadString (SREGsUserName);
CloseKey;
end;
if length(sBackImage)=0 then
begin
RootKey:=HKEY_CURRENT_USER;
if OpenKey('Control Panel/Desktop',True) then
begin
if ValueExists('Wallpaper') then
sBackImage:=ReadString('Wallpaper');
CloseKey;
end;
end;
//if
end;
//with
result:=true;
finally
Reg.Free;
end;
end;
function SaveSetting:boolean;
//保存当前设置到注册表
var
Reg: TRegistry;
begin
Reg := TRegistry.Create;
try
with Reg do
begin
RootKey := HKEY_LOCAL_MACHINE;
if OpenKey(SREGSubKey+SAppName,True) then
begin
WriteBool (SREGbSaveUserName, bSaveUserName);
WriteBool (SREGbUseFlatHint, bUseFlatHint);
WriteBool (SREGbUseHint, bUseHint);
WriteBool (SREGbUseXPMenu, bUseXPMenu);
WriteInteger(SREGclBackColor, clBackColor);
WriteInteger(SREGiDrawStyle, iDrawStyle);
WriteInteger(SREGiDropDownCount, iDropDownCount);
WriteString (SREGsBackImage, sBackImage);
WriteString (SREGsDataBaseName, sDataBaseName);
WriteString (SREGsUserName, sUserName);
CloseKey;
end;
end;
//with
result:=true;
finally
Reg.Free;
end;
end;