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

📄 usecdialogs.pas

📁 一个基于不需引擎的文件管理系统,使用了许多界面比较好的控件
💻 PAS
字号:
unit uSecDialogs;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, StdCtrls, ExtCtrls, TypInfo;

type
  TSecDialog=class(TComponent)
  private
    FOnFind: TNotifyEvent;
    FOnAfterCreateDialog: TNotifyEvent;
    procedure SetOnFind(const Value: TNotifyEvent);
    procedure SetOnAfterCreateDialog(const Value: TNotifyEvent);
    procedure SetFindText(const Value: string);
    function GetFindText:string;
    function GetOptions:TFindOptions;
    procedure DoOnAfterCreateDialog(sender:TObject);virtual;abstract;
    procedure CheckDialogType;
  protected
    FFrm:TForm;
    FFindText: string;
    FOptions: TFindOptions;
    IsReplace:Boolean;
  public
    constructor create(Aowner:TComponent);override;
    destructor destroy;override;
    procedure Execute;virtual;
    property FindText:string read GetFindText write SetFindText;
    property OnAfterCreateDialog:TNotifyEvent read FOnAfterCreateDialog write SetOnAfterCreateDialog;
    property Options: TFindOptions read GetOptions write FOptions;
    property OnFind:TNotifyEvent read FOnFind write SetOnFind;
  end;

  TSecFindDialog=class(TSecDialog)
  private
    procedure DoOnAfterCreateDialog(sender:TObject);override;
  protected
  
  public
    procedure Execute;override;
  published
    property OnFind;
  end;

  TSecReplaceDialog=class(TSecFindDialog)
  private
    FOnReplace: TNotifyEvent;
    FReplaceText: string;
    procedure SetOnReplace(const Value: TNotifyEvent);
    procedure SetReplaceText(const Value: string);
    function GetReplaceText:string;
    procedure DoOnAfterCreateDialog(sender:TObject);override;
  public
    procedure Execute;override;
    property ReplaceText:string read GetReplaceText write SetReplaceText;
  published
    property OnFind;
    property OnReplace:TNotifyEvent read FOnReplace write SetOnReplace;
  end;

implementation

uses uSecFindDialogs,uSecReplaceDialogs;


{ TSecFindDialog }

procedure TSecFindDialog.DoOnAfterCreateDialog(sender: TObject);
begin
  if (FFindText<>'') and (FFindText<>TSecFindFrm(Ffrm).FindText) then
    TSecFindFrm(Ffrm).Edit1.Text:=FFindText;

  if (FOptions<>[]) and (FOptions<>TSecFindFrm(Ffrm).Options) then
  begin
    if frMatchCase in FOptions then
      TSecFindFrm(Ffrm).CheckBox1.Checked:=true;
    if frDown in FOptions then
      TSecFindFrm(Ffrm).RadioGroup1.ItemIndex:=1
    else
      TSecFindFrm(Ffrm).RadioGroup1.ItemIndex:=0;
  end;
end;

procedure TSecFindDialog.Execute;
begin
  inherited;
end;

{ TSecReplaceDialog }

procedure TSecReplaceDialog.DoOnAfterCreateDialog(sender: TObject);
begin
  if (FFindText<>'') and (FFindText<>TSecReplaceFrm(Ffrm).FindText) then
    TSecReplaceFrm(Ffrm).Edit1.Text:=FFindText;

  if (FReplaceText<>'') and (FReplaceText<>TSecReplaceFrm(Ffrm).ReplaceText) then
    TSecReplaceFrm(Ffrm).Edit2.Text:=FReplaceText;

  if (FOptions<>[]) and (FOptions<>TSecReplaceFrm(Ffrm).Options) then
  begin
    if frMatchCase in FOptions then
      TSecReplaceFrm(Ffrm).CheckBox1.Checked:=true;
  end;
end;

procedure TSecReplaceDialog.Execute;
begin
  inherited;
end;

function TSecReplaceDialog.GetReplaceText: string;
begin
  if FFrm<>nil then
  begin
    FReplaceText:=TSecReplaceFrm(FFrm).ReplaceText;
    result:=TSecReplaceFrm(FFrm).ReplaceText;
  end
  else
    result:=FReplaceText;
end;

procedure TSecReplaceDialog.SetOnReplace(const Value: TNotifyEvent);
begin
  FOnReplace := Value;
end;

procedure TSecReplaceDialog.SetReplaceText(const Value: string);
begin
  FReplaceText := Value;
end;

{ TSecDialog }

procedure TSecDialog.CheckDialogType;
var
  PropList:PPropList;
  ClassTypeData:PTypeData;
  i:integer;
begin
  ClassTypeData:=GetTypeData(ClassInfo);
  GetMem(PropList,SizeOf(PPropInfo)*ClassTypeData.PropCount);
  GetPropInfos(ClassInfo,PropList);
  IsReplace:=false;
  for i:=0 to ClassTypeData.PropCount-1 do
    if PropList[i]^.Name='OnReplace' then
    begin
      IsReplace:=true;
      break;
    end;
  FreeMem(PropList,SizeOf(PPropInfo)*ClassTypeData.PropCount);    
end;

constructor TSecDialog.create(Aowner: TComponent);
begin
  inherited create(Aowner);
  CheckDialogType;   
  OnAfterCreateDialog:=DoOnAfterCreateDialog;
end;

destructor TSecDialog.destroy;
begin
  inherited destroy;
end;

procedure TSecDialog.Execute;
begin
  if FFrm=nil then
  begin
    if not IsReplace then
      Ffrm:=TSecFindFrm.create(self)
    else
      Ffrm:=TSecReplaceFrm.Create(self);
  end;
  if Assigned(FOnAfterCreateDialog) then
    FOnAfterCreateDialog(self);
  Ffrm.ShowModal;
  FreeAndnil(Ffrm);
end;

function TSecDialog.GetFindText: string;
begin
  if FFrm<>nil then
  begin
    if not IsReplace then
    begin
      FFindText:=TSecFindFrm(FFrm).FindText;
      result:=TSecFindFrm(FFrm).FindText;
    end
    else
    begin
      FFindText:=TSecReplaceFrm(FFrm).FindText;
      result:=TSecReplaceFrm(FFrm).FindText;
    end;
  end
  else
    result:=FFindText;
end;

function TSecDialog.GetOptions: TFindOptions;
begin
  if FFrm<>nil then
  begin
    if not IsReplace then
    begin
      FOptions:=TSecFindFrm(FFrm).Options;
      result:=TSecFindFrm(FFrm).Options;
    end
    else
    begin
      FOptions:=TSecReplaceFrm(FFrm).Options;
      result:=TSecReplaceFrm(FFrm).Options;
    end;
  end
  else
    result:=FOptions;
end;

procedure TSecDialog.SetFindText(const Value: string);
begin
  FFindText := Value;
  if FFrm<>nil then
  begin
    if not IsReplace then
      TSecFindFrm(FFrm).Edit1.Text:=Value
    else
      TSecReplaceFrm(FFrm).Edit1.Text:=Value;
  end;
end;

procedure TSecDialog.SetOnAfterCreateDialog(const Value: TNotifyEvent);
begin
  FOnAfterCreateDialog := Value;
end;

procedure TSecDialog.SetOnFind(const Value: TNotifyEvent);
begin
  FOnFind := Value;
end;

end.

⌨️ 快捷键说明

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