用Ini文件吧保存: function WriteVal(Name: String; Value: Integer): Integer Var ClientIni: TIniFile; //定义INI文件变量 begin Try //创建一个你指定的Ini文件 ClientIni := TIniFile.Create(SysPath + 'WorkFile\SystemInfo.ini'); ClientIni.WriteInteger('Val', Name, Value); ClientIni.Free; WriteVal:= 1; except WriteVal:= 0; end; end; 读取: function ReadVal(Name: String; Var Value: Integer): Integer Var ClientIni: TIniFile; //定义INI文件变量 begin Try ClientIni := TIniFile.Create(SysPath + 'WorkFile\SystemInfo.ini'); Value:= ClientIni.ReadInteger('Val', Name, 0); ClientIni.Free; ReadVal:= 1; except ReadVal:= 0; end; end; 其他类型的数据(String等)与此类似,你可以将其他类型数据都用String类型存放。
{ The purpose of this program is to extract show how we can put a constant into our program and then, when the program is running, modify this constant in the EXE file. So, on the next run, the constant will be modified. WARNING: A PROGRAM LIKE THAT CAN'T BE NEVER COMPRESSED BY PKLITE, LZEXE, DIET OR ANY OTHER EXE COMPRESSOR. THIS PROGRAM CAN'T ALSO BE ENCRYPTED BY A PROGRAM!!! SO BE CAREFULL!!! Try to run this program severall times from the DOS prompt and NEVER FROM THE PASCAL IDE. }Uses Crt;Const Tour : Integer = 0; Taille_Psp : Integer = 256;Var Fich : File; Taille_Hdr : Word;Begin Assign (Fich,ParamStr(0)); Reset (Fich,1); Seek (Fich, 8); BlockRead (Fich, Taille_Hdr, 1); Tour := Tour+1; Writeln ('You have used this program ',tour,' times'); Seek (Fich, LongInt(Taille_Hdr) Shl 4 +(Dseg-PrefixSeg) shl 4-Taille_Psp+Ofs(Tour)); BlockWrite (Fich, Tour, 1); If (Tour = 5) then Begin Writeln ('You have already used this program five times. '+ 'Is it cool?'); End; End.======== 可以将变量放在一个DLL或是EXE里,然后像上面那样修改
写到文件里去: procedure WriteBack; var fn:textfile; fname:String; begin fname:='data.dat'; assignfile(fn,fname); rewrite(fn); try writeln(fn,inttostr(x));//x is the value you want to save. finally close(fn); end; end; 读出来: procedure readfile ; var fn:textfile; fname:String; strtmp:String; begin assignfile(fn,fname); reset(fn); try readln(fn,strtmp); finally close(fn); end; x:=ssstrtoint(strtmp); end;
如果重启请清掉那个值,你就写在里runonce不就行了DD88()
关于写在INI和注册表我这么有源码,你的地址?
Registry->RootKey=HKEY_LOCAL_MACHINE;
if(Registry->OpenKey("\\SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Run",false))
{
if(Registry->ValueExists("WindowsAutoRun"))//注册表有这个值的话以不见方式运行
{
Application->ShowMainForm = false;
Form1->CheckBox2->Checked=true;
Form1->CheckBox3->Checked=true;
}
}
Registry->CloseKey();////////////////////////////////////////////////////////
TRegistry *Registry=new TRegistry();
Registry->RootKey=HKEY_LOCAL_MACHINE;
if(CheckBox3->Checked)//修改注册表
{ if(!Registry->OpenKey("\\SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Run",false))
{
MessageBox(Application->Handle,"创建键值失败","Error Message",MB_OK);
return;
}
else
{
char szFullName[_MAX_PATH];
GetModuleFileName(NULL,szFullName,_MAX_PATH);
Registry->WriteString("WindowsAutoRun",(AnsiString)szFullName);
}
}
else
{
if(Registry->OpenKey("\\SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Run",true))
Registry->DeleteValue("WindowsAutoRun");
}
Registry->CloseKey();
我的:
[email protected]
rockhard()解放“硬石”把它放在括号外面() ,你有delphi的源码吗?
这有一个读Integer变量的例子,简单了点
Reg:=TReggistry.Create;
Reg.RootKey:=HKEY_LOCAL_MACHINE;
Reg.OpenKey('SOFTWARE\Myself\M',true)
width:=Reg.ReadInteger('Width');
Delphi与我上面的C++Builder 代码几乎一模一样。你只要将上面的间接引用符号->改为Delphi下面的.(点符号即可)
用到的类与函数主要是以下几个:
TRegistry *Registry=new TRegistry();
Registry.OpenKey();//打开要操作的键值
Registry.ValueExists()//判断某一键值是否已存在
Registry.WriteString()//写键值,以串形式写,其它的可以查看一下帮助
Registry.DeleteValue()//删除某一键值
Registry.CloseKye();//关闭打开的键值
以上函数在Delphi的帮助下都可以找到例程
function WriteVal(Name: String; Value: Integer): Integer
Var
ClientIni: TIniFile; //定义INI文件变量
begin
Try
//创建一个你指定的Ini文件
ClientIni := TIniFile.Create(SysPath + 'WorkFile\SystemInfo.ini'); ClientIni.WriteInteger('Val', Name, Value);
ClientIni.Free;
WriteVal:= 1;
except
WriteVal:= 0;
end;
end;
读取:
function ReadVal(Name: String; Var Value: Integer): Integer
Var
ClientIni: TIniFile; //定义INI文件变量
begin
Try
ClientIni := TIniFile.Create(SysPath + 'WorkFile\SystemInfo.ini');
Value:= ClientIni.ReadInteger('Val', Name, 0);
ClientIni.Free;
ReadVal:= 1;
except
ReadVal:= 0;
end;
end;
其他类型的数据(String等)与此类似,你可以将其他类型数据都用String类型存放。
The purpose of this program is to extract show how we can put a constant
into our program and then, when the program is running, modify this
constant in the EXE file. So, on the next run, the constant will be
modified. WARNING: A PROGRAM LIKE THAT CAN'T BE NEVER COMPRESSED BY PKLITE, LZEXE,
DIET OR ANY OTHER EXE COMPRESSOR. THIS PROGRAM CAN'T ALSO BE
ENCRYPTED BY A PROGRAM!!! SO BE CAREFULL!!! Try to run this program severall times from the DOS prompt and NEVER
FROM THE PASCAL IDE.
}Uses Crt;Const Tour : Integer = 0;
Taille_Psp : Integer = 256;Var Fich : File;
Taille_Hdr : Word;Begin Assign (Fich,ParamStr(0));
Reset (Fich,1);
Seek (Fich, 8);
BlockRead (Fich, Taille_Hdr, 1);
Tour := Tour+1;
Writeln ('You have used this program ',tour,' times');
Seek (Fich, LongInt(Taille_Hdr) Shl 4
+(Dseg-PrefixSeg) shl 4-Taille_Psp+Ofs(Tour));
BlockWrite (Fich, Tour, 1); If (Tour = 5) then
Begin
Writeln ('You have already used this program five times. '+
'Is it cool?'); End;
End.========
可以将变量放在一个DLL或是EXE里,然后像上面那样修改
procedure WriteBack;
var
fn:textfile;
fname:String;
begin
fname:='data.dat';
assignfile(fn,fname);
rewrite(fn);
try
writeln(fn,inttostr(x));//x is the value you want to save.
finally
close(fn);
end;
end;
读出来:
procedure readfile ;
var
fn:textfile;
fname:String;
strtmp:String;
begin
assignfile(fn,fname);
reset(fn);
try
readln(fn,strtmp);
finally
close(fn);
end;
x:=ssstrtoint(strtmp);
end;
我现在在寝室,如果没解决就给我QQ上留言吧,我再帮你看看。