Solved

Implement Registry

Posted on 2010-09-23
5
283 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
ID: 33750735
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
ID: 33764695
moved code into code snippet?
whats the meaning of that aikimark?
0
 
LVL 14

Author Comment

by:systan
ID: 33766125
Ah, Ok, I've noticed it.
Thanks.
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Objective: - This article will help user in how to convert their numeric value become words. How to use 1. You can copy this code in your Unit as function 2. than you can perform your function by type this code The Code   (CODE) The Im…
Introduction The parallel port is a very commonly known port, it was widely used to connect a printer to the PC, if you look at the back of your computer, for those who don't have newer computers, there will be a port with 25 pins and a small print…
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …

948 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

22 Experts available now in Live!

Get 1:1 Help Now