Solved

Implement Registry

Posted on 2010-09-23
5
285 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

Courses: Start Training Online With Pros, Today

Brush up on the basics or master the advanced techniques required to earn essential industry certifications, with Courses. Enroll in a course and start learning today. Training topics range from Android App Dev to the Xen Virtualization Platform.

Question has a verified solution.

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

This article explains how to create forms/units independent of other forms/units object names in a delphi project. Have you ever created a form for user input in a Delphi project and then had the need to have that same form in a other Delphi proj…
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…
This tutorial gives a high-level tour of the interface of Marketo (a marketing automation tool to help businesses track and engage prospective customers and drive them to purchase). You will see the main areas including Marketing Activities, Design …
Migrating to Microsoft Office 365 is becoming increasingly popular for organizations both large and small. If you have made the leap to Microsoft’s cloud platform, you know that you will need to create a corporate email signature for your Office 365…

816 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