⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 dcinternal.pas

📁 DiskControls.v3.8.Full.Source 控制磁盘的控件 包括源代码
💻 PAS
📖 第 1 页 / 共 2 页
字号:
{*******************************************************************************

  Disk Controls pack v3.5
  FILE: dcInternal.pas - Base ancestor class, TumdcComponent

  Copyright (c) 1999-2002 UtilMind Solutions
  All rights reserved.
  E-Mail: info@appcontrols.com, info@utilmind.com
  WWW: http://www.appcontrols.com, http://www.utilmind.com

  The entire contents of this file is protected by International Copyright
Laws. Unauthorized reproduction, reverse-engineering, and distribution of all
or any portion of the code contained in this file is strictly prohibited and
may result in severe civil and criminal penalties and will be prosecuted to
the maximum extent possible under the law.

*******************************************************************************}
{$I umDefines.inc}

unit dcInternal;

interface

uses
  Classes, Graphics, Registry
  {$IFDEF USEINIFILES},IniFiles{$ENDIF};

type
  TdcFileSize = {$IFNDEF D4}Extended{$ELSE}Int64{$ENDIF};

  TdcScanAttribute = (saNormal, saArchive, saReadOnly, saHidden, saSystem, saDirectory, saAny);
  TdcScanAttributes = set of TdcScanAttribute;

  { TdcRegistrySaver }
  TdcRegSaverOptions = set of (saveOnClose, saveOnMoveResize);
  TdcRegLocation = (rCurrentUser, rLocalMachine);
  {$IFDEF USEINIFILES}
  TdcStorageType = (useRegistry, useIniFile);
  {$ENDIF}
  TdcRegistrySaver = class(TPersistent)
  private
    FEnabled: Boolean;
    {$IFDEF USEINIFILES}
    FIniFileName, FIniSection: String;
    {$ENDIF}
    FOptions: TdcRegSaverOptions;
    FRegKey: String;
    FRegLocation: TdcRegLocation;
    {$IFDEF USEINIFILES}
    FStorage: TdcStorageType;
    {$ENDIF}

    { for internal use }
    FOwner: TComponent;

    function  IsStoreRegKey: Boolean;
    procedure SetRegKey(const Value: String);
  protected
    procedure DoSaveToRegistry(Reg: TRegistry); virtual; abstract;
    procedure DoLoadFromRegistry(Reg: TRegistry); virtual; abstract;

    {$IFDEF USEINIFILES}
    procedure DoSaveToIniFile(Ini: TIniFile); virtual; abstract;
    procedure DoLoadFromIniFile(Ini: TIniFile); virtual; abstract;
    {$ENDIF}
  public
    constructor Create(aOwner: TComponent); virtual;

    procedure Save; virtual;
    procedure Load; virtual;

    property Owner: TComponent read FOwner;
  published
    property Enabled: Boolean read FEnabled write FEnabled default False;
    {$IFDEF USEINIFILES}
    property IniFileName: String read FIniFileName write FIniFileName;
    property IniSection: String read FIniSection write FIniSection;
    {$ENDIF}
    property Options: TdcRegSaverOptions read FOptions write FOptions default [saveOnClose];
    property RegKey: String read FRegKey write SetRegKey stored IsStoreRegKey;
    property RegLocation: TdcRegLocation read FRegLocation write FRegLocation default rCurrentUser;
    {$IFDEF USEINIFILES}
    property Storage: TdcStorageType read FStorage write FStorage default useRegistry;
    {$ENDIF}
  end;

  { TdcUniqueList (the TList descendant which can contain only unique pointers (Items) }
  TdcUniqueList = class(TList)
  public
    function Add(Item: Pointer): Integer;
    procedure Insert(Index: Integer; Item: Pointer);
  end;

  { TdcObjectList (the list which:
     1. Can contain only unique items (this because it's successor of TdcUniqueList)
     2. Operate only with Objects instead of Pointers
     3. Owns objects and destroy then on removing
     4. Have protected "IsCanAddItem" function which can be overriden to check whether item can or cannot be added for some reason }
  TdcObjectListItemEvent = procedure(Sender: TObject; Item: TObject) of object;
  TdcObjectList = class(TdcUniqueList)
  private
    FOwnsObjects: Boolean;
{$IFDEF D5}
    FOnAdded,
    FOnDeleted: TdcObjectListItemEvent;
    FOnChanged: TNotifyEvent;
{$ENDIF}
  protected
{$IFDEF D4}
    FOwner: TObject;
{$ENDIF}

    function IsCanAddItem(Item: TObject): Boolean; virtual;
{$IFDEF D5}
    procedure Notify(Ptr: Pointer; Action: TListNotification); override;
    procedure DoAdded(Item: TObject); virtual;
    procedure DoDeleted(Item: TObject); virtual;
    procedure DoChanged; virtual;
{$ENDIF}
{$IFDEF D4}
    procedure Initialize; virtual;
    procedure LoadItemFromStream(Stream: TStream); virtual;
    procedure SaveItemToStream(Index: Integer; Stream: TStream); virtual;
{$ENDIF}
  public
    constructor Create; {$IFDEF D4} overload;
    constructor Create(AOwnsObjects: Boolean; AOwner: TObject = nil); overload;
    constructor Create(AStream: TStream; AOwnsObjects: Boolean = True; AOwner: TObject = nil); overload; {$ENDIF}
{$IFNDEF D5}
    destructor Destroy; override;
    procedure Clear; {$IFDEF D4} override; {$ENDIF}
{$ENDIF}
    function Add(Item: TObject): Integer;
    function Remove(Item: TObject {$IFDEF D4}; ReleaseInstance: Boolean = True {$ENDIF}): Integer;
    procedure Delete(Index: Integer {$IFDEF D4}; ReleaseInstance: Boolean = True {$ENDIF});
    function IndexOf(Item: TObject): Integer;
    procedure Insert(Index: Integer; Item: TObject);
    function FindInstanceOf(AClass: TClass; AExact: Boolean {$IFDEF D4} = True {$ENDIF}; AStartAt: Integer {$IFDEF D4} = 0 {$ENDIF}): Integer;

{$IFDEF D4}
    procedure LoadFromStream(Stream: TStream; Reset: Boolean = True); virtual;
    procedure SaveToStream(Stream: TStream); virtual;

    property Owner: TObject read FOwner;    
{$ENDIF}

    property OwnsObjects: Boolean read FOwnsObjects write FOwnsObjects default True;
{$IFDEF D5}
    property OnAdded: TdcObjectListItemEvent read FOnAdded write FOnAdded;
    property OnDeleted: TdcObjectListItemEvent read FOnDeleted write FOnDeleted;
    property OnChanged: TNotifyEvent read FOnChanged write FOnChanged;
{$ENDIF}
  end;

{$IFDEF D4}
  { TdcListObject }
  TdcListObject = class(TPersistent)
  private
    FOwner: TdcObjectList;
  protected
    procedure Initialize(AObject: TObject); virtual;
  public
    Data: Pointer;

    constructor Create(aOwner: TdcObjectList; Stream: TStream = nil; AObject: TObject = nil); virtual;

    procedure LoadFromStream(Stream: TStream; AObject: TObject = nil); virtual;
    procedure SaveToStream(Stream: TStream); virtual;

    property Owner: TdcObjectList read FOwner;
  end;
{$ENDIF}  

// Base DiskControls class
  TumdcComponent = class(TComponent)
  private
    FAbout: String;
  public
    {$IFDEF TRIAL}
    constructor Create(aOwner: TComponent); override;
    {$ENDIF}

    property About: String read FAbout write FAbout stored False;
  end;

implementation

uses Windows, Forms, SysUtils {$IFNDEF D5},dcUtils{$ENDIF};

const
  DEF_REGKEY   = '\Software\CompanyName\ProgramName\Default';
{$IFDEF USEINIFILES}
  ERROR_NO_INI = '.INI file not specified';
{$ENDIF}

{$IFDEF TRIAL}
var
  NotifyDone: Boolean = False;
{$ENDIF}

{ TdcRegistrySaver }
constructor TdcRegistrySaver.Create(aOwner: TComponent);
begin
  inherited Create;
  FOwner := aOwner;

  FOptions := [saveOnClose];
  FRegKey := DEF_REGKEY;
end;

procedure TdcRegistrySaver.Save;
var
  Reg: TRegistry;
{$IFDEF USEINIFILES}
  Ini: TIniFile;
{$ENDIF}
begin
  if not FEnabled or (csDesigning in Owner.ComponentState) then Exit;

{$IFDEF USEINIFILES}
  if Storage = useRegistry then
   begin
{$ENDIF}
    Reg := TRegistry.Create;
    with Reg do
     try
       try
         if FRegLocation = rCurrentUser then
           RootKey := HKEY_CURRENT_USER
         else
           RootKey := HKEY_LOCAL_MACHINE;
         if OpenKey(FRegKey, True) then
           DoSaveToRegistry(Reg);
       except
       end;
     finally
       Free;
     end;
{$IFDEF USEINIFILES}     
   end
  else
   begin
    if FIniFileName = '' then
      raise Exception.Create(ERROR_NO_INI);

    Ini := TIniFile.Create(FIniFileName);
    try
      try
        DoSaveToIniFile(Ini);
      except
      end;
    finally
      Ini.Free;
    end;
   end;
{$ENDIF}   
end;

procedure TdcRegistrySaver.Load;
var
  Reg: TRegistry;
{$IFDEF USEINIFILES}
  Ini: TIniFile;
{$ENDIF}
begin
  if not FEnabled or (csDesigning in Owner.ComponentState) then Exit;

{$IFDEF USEINIFILES}
  if Storage = useRegistry then
   begin
{$ENDIF}
    Reg := TRegistry.Create;
    with Reg do
     try
       try
         if FRegLocation = rCurrentUser then
           RootKey := HKEY_CURRENT_USER
         else
           RootKey := HKEY_LOCAL_MACHINE;
         if OpenKey(FRegKey, False) then
           DoLoadFromRegistry(Reg);
       except
       end;
     finally
       Free;
     end;
{$IFDEF USEINIFILES}     
   end
  else
   begin
    if FIniFileName = '' then

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -