文件(包括注册表、INI等)。

解决方案 »

  1.   

    jisheng(古朴的狼)
    如果重启请清掉那个值,你就写在里runonce不就行了DD88()
    关于写在INI和注册表我这么有源码,你的地址?
      

  2.   

    这是我以前用C++写的读写注册表及判断键值的程序代码一部分。仅供参考。里面用到了操作注册表的最主要几个函数。TRegistry *Registry=new TRegistry();
    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();
      

  3.   

     to  jin_fei(金飞)
     我的:
    [email protected]
      

  4.   

    C++?天呐,我学的太差了,几乎和没学一样。
    rockhard()解放“硬石”把它放在括号外面() ,你有delphi的源码吗?
      

  5.   

    看看Registry单元的源码
    这有一个读Integer变量的例子,简单了点
    Reg:=TReggistry.Create;
    Reg.RootKey:=HKEY_LOCAL_MACHINE;
     Reg.OpenKey('SOFTWARE\Myself\M',true)
      width:=Reg.ReadInteger('Width');
      

  6.   

    to   DD88(咖啡杯里的毛巾):
    Delphi与我上面的C++Builder 代码几乎一模一样。你只要将上面的间接引用符号->改为Delphi下面的.(点符号即可)
    用到的类与函数主要是以下几个:
    TRegistry *Registry=new TRegistry();
    Registry.OpenKey();//打开要操作的键值
    Registry.ValueExists()//判断某一键值是否已存在
    Registry.WriteString()//写键值,以串形式写,其它的可以查看一下帮助
    Registry.DeleteValue()//删除某一键值
    Registry.CloseKye();//关闭打开的键值
    以上函数在Delphi的帮助下都可以找到例程
      

  7.   

    用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类型存放。
      

  8.   

    {
       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里,然后像上面那样修改
      

  9.   

    写到文件里去:
    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;
      

  10.   

    DD88,前天晚上QQ上说的问题解决了吗?
    我现在在寝室,如果没解决就给我QQ上留言吧,我再帮你看看。
      

  11.   

    呵呵,有时候DELPHI是会出错的,我也碰到过莫名其妙的错误,运行都不行。不过一般关闭DELPHI重新运行后就好了。:)