Solved

Implement Registry

Posted on 2010-09-23
5
280 Views
Last Modified: 2012-06-21
http://www.experts-exchange.com/Programming/Languages/Pascal/Delphi/Q_22015173.html

That is the link of rllibbys answer for registry cleaning
Units are regsweeper and regutils

Can someone show me a simple application form using the regsweeper.

Thanks
0
Comment
Question by:systan
  • 2
5 Comments
 
LVL 32

Accepted Solution

by:
ewangoya earned 500 total points
Comment Utility
Heres my intepretation, and mmm I didn't test it


unit Unit1;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, StdCtrls, RegUtils, RegSweeper;

type
  TForm1 = class(TForm)
    btnScan: TButton;
    btnFix: TButton;
    btnCancel: TButton;
    Memo1: TMemo;
    procedure btnScanClick(Sender: TObject);
    procedure btnFixClick(Sender: TObject);
    procedure btnCancelClick(Sender: TObject);
  private
    FCanceled: Boolean;
    procedure StartFix(Sender: TObject; Count: Integer);
    procedure FinishFix(Sender: TObject; Fixed: Integer; Cancelled: Boolean);
    procedure StartScan(Sender: TObject);
    procedure FinishScan(Sender: TObject; Cancelled: Boolean);
    procedure StartGroupItem(Sender: TObject; ItemName: String; var Cancel: Boolean);
    procedure FinishGroup(Sender: TObject; GroupItem: TRegGroupClass; Operation: TRegOperation; var Cancel: Boolean);
    procedure FixItem(Sender: TObject; ItemName: String; Fixed: Boolean; var Cancel: Boolean);
    procedure GroupItem(Sender: TObject; ItemName: String; var Cancel: Boolean);
  public
    { Public declarations }
  end;

var
  Form1: TForm1;

implementation

{$R *.dfm}

{ TForm1 }

procedure TForm1.btnScanClick(Sender: TObject);
var
  RegSweeper: TRegSweeper;
begin
  try
    RegSweeper := TRegSweeper.Create;
    RegSweeper.OnGroupStart := StartGroupItem;
    RegSweeper.OnGroupItem := GroupItem;
    RegSweeper.OnGroupFinish := FinishGroup;
    RegSweeper.OnScanFinish := FinishScan;
    RegSweeper.OnScanStart := StartScan;
    RegSweeper.Scan;
  finally
    FreeAndNil(RegSweeper);
  end;
end;

procedure TForm1.btnFixClick(Sender: TObject);
var
  RegSweeper: TRegSweeper;
  Stream: TFileStream;
begin
  Stream := TFileStream.Create('c:\mybackup.reg', fmCreate);
  try
    try
      RegSweeper := TRegSweeper.Create;
      RegSweeper.OnGroupStart := StartGroupItem;
      RegSweeper.OnGroupItem := GroupItem;
      RegSweeper.OnGroupFinish := FinishGroup;
      RegSweeper.OnFixStart := StartFix;
      RegSweeper.OnFixItem := FixItem;
      RegSweeper.OnFixFinish := FinishFix;

      RegSweeper.Fix(Stream);
    finally
      FreeAndNil(RegSweeper);
    end;
  finally
    FreeAndNil(Stream);
  end;
end;

procedure TForm1.btnCancelClick(Sender: TObject);
begin
  FCanceled := True;
end;

procedure TForm1.FinishFix(Sender: TObject; Fixed: Integer; Cancelled: Boolean);
begin
  if Cancelled then
    Memo1.Lines.Add('User cancelled')
  else
    Memo1.Lines.Add('Finished fixing registry')
end;

procedure TForm1.FinishGroup(Sender: TObject; GroupItem: TRegGroupClass;
  Operation: TRegOperation; var Cancel: Boolean);
begin
  Cancel := FCanceled;
  if FCanceled then
    Exit;
  if Operation = roValidate then
    Memo1.Lines.Add('Finished validating group: ' + RegGroupClassName(GroupItem))
  else
    Memo1.Lines.Add('Finished loading group: ' + RegGroupClassName(GroupItem))
end;

procedure TForm1.FinishScan(Sender: TObject; Cancelled: Boolean);
begin
  if Cancelled then
    Memo1.Lines.Add('User cancelled')
  else
    Memo1.Lines.Add('Finished scanning registry')
end;

procedure TForm1.FixItem(Sender: TObject; ItemName: String; Fixed: Boolean;
  var Cancel: Boolean);
begin
  Cancel := FCanceled;
  if FCanceled then
    Exit;
  Memo1.Lines.Add('Fixing item: ' + ItemName);
end;

procedure TForm1.StartFix(Sender: TObject; Count: Integer);
begin
  Memo1.Lines.Clear;
  Memo1.Lines.Add('Started fix')
end;

procedure TForm1.StartGroupItem(Sender: TObject; ItemName: String;
  var Cancel: Boolean);
begin
  Cancel := FCanceled;
  if FCanceled  then
    Exit;
  Memo1.Lines.Add('Working on item: ' + ItemName)
end;

procedure TForm1.StartScan(Sender: TObject);
begin
  Memo1.Lines.Clear;
  Memo1.Lines.Add('Started Scan');
end;

end.

//dfm
object Form1: TForm1
  Left = 0
  Top = 0
  Caption = 'Form1'
  ClientHeight = 379
  ClientWidth = 512
  Color = clBtnFace
  Font.Charset = DEFAULT_CHARSET
  Font.Color = clWindowText
  Font.Height = -11
  Font.Name = 'Tahoma'
  Font.Style = []
  OldCreateOrder = False
  PixelsPerInch = 96
  TextHeight = 13
  object btnScan: TButton
    Left = 360
    Top = 24
    Width = 121
    Height = 25
    Caption = 'Scan'
    TabOrder = 0
    OnClick = btnScanClick
  end
  object btnFix: TButton
    Left = 360
    Top = 71
    Width = 121
    Height = 25
    Caption = 'Backup && Fix'
    TabOrder = 1
    OnClick = btnFixClick
  end
  object btnCancel: TButton
    Left = 360
    Top = 120
    Width = 121
    Height = 25
    Caption = 'Cancel'
    TabOrder = 2
    OnClick = btnCancelClick
  end
  object Memo1: TMemo
    Left = 16
    Top = 16
    Width = 329
    Height = 345
    Lines.Strings = (
      '')
    TabOrder = 3
  end
end

Open in new window

0
 
LVL 14

Author Comment

by:systan
Comment Utility
moved code into code snippet?
whats the meaning of that aikimark?
0
 
LVL 14

Author Comment

by:systan
Comment Utility
Ah, Ok, I've noticed it.
Thanks.
0

Featured Post

Highfive + Dolby Voice = No More Audio Complaints!

Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

Join & Write a Comment

Have you ever had your Delphi form/application just hanging while waiting for data to load? This is the article to read if you want to learn some things about adding threads for data loading in the background. First, I'll setup a general applica…
Introduction I have seen many questions in this Delphi topic area where queries in threads are needed or suggested. I know bumped into a similar need. This article will address some of the concepts when dealing with a multithreaded delphi database…
This video discusses moving either the default database or any database to a new volume.
Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…

762 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

8 Experts available now in Live!

Get 1:1 Help Now