对注册表进行增减键值操作后,再把键值显示在listBox中,便无法显示更新后的数据,只有退出整个应用程序后,再进入,才能显示刚才增减的键值。...
代码如下
procedure TFm_Register.FormCreate(Sender: TObject);
var
   Reg: TRegistry;  
   Val:TStringList;
  I:Integer;
begin
  Reg:=TRegistry.Create;
  try
    Val:=TStringList.Create;
    try
      Reg.RootKey:=HKey_Current_User; // Section to look for within the registry
      if not Reg.OpenKey('dTest',False) then
        //ShowMessage('Error opening key')
        reg.CreateKey('Dtest')
      else
      begin
        Reg.OpenKey('Dtest',false);
        Reg.GetKeyNames(Val);
        ListBox1.Clear;
        for I:=0 to Val.Count-1 do
        begin
          ListBox1.Items.Add(Val.Strings[I]);
        end;
      end;
    finally
      Val.Free;
    end;
  finally
    Reg.Free;
  end;
end;

解决方案 »

  1.   

    registrytemp:tregistry;
    curdate:tdate;
    bootkey:integer;
    begin
      registrytemp:=tregistry.Create;
      if not registrytemp.OpenKey('software\mysoftware',False) then registrytemp.CreateKey('software\mysoftware');
      with registrytemp do
      begin
        RootKey:=HKEY_LOCAL_MACHINE;
        if openkey('software\mysoftware',true) then
        begin
          if readbool('runned') then
          begin
            curdate:=date;
            begin
              if (curdate-readtime('lastruntime')>=readinteger('durtation')) then
              begin
                showmessage('试用期已过');
                exit;
              end
              else
              begin
                deletekey('lastruntime');
                writetime('lastruntime',date);
                self.Caption:='小灵通分析软件测试版,还剩:'+datetimetostr(curdate-readtime('lastruntime'));
              end;
            end;
          end
          else
          begin
            deletekey('runned');
            writebool('runned',true);
            writeinteger('durtation',10);
            writetime('lastruntime',date);
          end;
          end
        else
        begin
          showmessage('fails!');
        end;
        end;错误通不过,为什么,
      

  2.   

    if readbool('runned') then
    里面的runned到底是什么回事,我抄来的程序,请解释,并如何解,
      

  3.   

    registrytemp:=tregistry.Create;
    registrytemp.RootKey:=HKEY_LOCAL_MACHINE; //加上这一句,否则下面的openkey怎么知道open哪个根键下的key呢?
      if not registrytemp.OpenKey('software\mysoftware',False) then registrytemp.CreateKey('software\mysoftware');if readbool('runned') then
    runned是布尔型的数据,所以读出的结果可以直接放到逻辑判断式中;实际就是:
    if readbool('runned')=true thento: Cybernet(cyberboy.net)
    你的程序写的没问题呀。但你读注册表的过程写在FormCreate中,这个Form如果不被free掉再重新创建,就无法读出新的键值;尤其如果这个form是主form,那么只有退出程序重新运行程序才能读出新的键值。建议将这个过程单独写一个函数,在FormCreate中调用,需要刷新时再调用。