How to Clear Typed URL History

DTHLIEM
DTHLIEM used Ask the Experts™
on
Please see this code (not mine)

//***************************
   procedure TForm1.FormCreate(Sender: TObject);
Var
  reg:TRegistry;
  url:Integer;
  URL1:String;
begin
  listbox1.Clear ;
  reg:=TRegistry.Create;
  reg.RootKey:=HKEY_CURRENT_USER;
  reg.OpenKey('Software\Microsoft\Internet Explorer\TypedURLS',False);
  URL:=1;
  While URL<>1000 Do

  Begin
    URL1:=(reg.ReadString('url'+IntToStr(url)));
    If URL1='' Then URL:=1000

    Else
     Begin
     listbox1.Items.Add(URL1+IntToStr(url));
       Url:=Url+1;
     End;
  End;
  reg.CloseKey;
  reg.Free;
end;

//***************************
  I'll show value in listbox1. The question is how i can delete just reg.value is seleted in Listbox1.
      Not Clear all

Thanks.
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
DTHLIEM:


Add a button to the form and use this code. It will delete the selected key.


procedure TForm1.Button1Click(Sender: TObject);
Var
  CurrentItem:Integer;
  st : AnsiString;
  rega:TRegistryIniFile;
begin
{Get Selected Item index }
CurrentItem:=listbox1.ItemIndex;
rega:=TRegistryIniFile.Create('test');
{DeleteKey from registry}
 st:=trim('url'+IntToStr(CurrentItem+1));
 rega.DeleteKey('\Software\Microsoft\Internet Explorer\TypedURLS',st);
{delete it from the listbox}
 listbox1.Items.Delete(CurrentItem);

rega.Free;
end;


Note: if you delete a middle key like the number 5, your piece of code will not read properly next time the url's list due to a "bug" in the way it was coded. The loop is searching for an empty '' url key to end the cycle.

To avoid this "bug" do the following


1 - Get the total number of subkeys using:


reg.GetKeyInfo(var Value: TRegKeyInfo): Boolean;

 TregKeyInfo.NumSubKeys will return the total number of subkeys. This allow you to keep the cycle till you find the existent amount of keys, not a blank key that can be in the middle of the list breaking the ' While' cycle.

Best Regards

VOBJ7



Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial