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

📄 optionfrm.pas

📁 vVC显示图片 VC显示图片 VC显示图片 VC显示图片 VC显示图片
💻 PAS
字号:
unit OptionFrm;

interface

uses
  Windows, Messages, SysUtils, Classes, Graphics,
  Controls, Forms, Dialogs, StdCtrls, IniFiles,
  Registry;

type
  TOptions = record
    ShowWizardFirstPage: boolean;
    DelphiPrj: boolean;
    BcbPrj: boolean;
    VbPrj: boolean;
  end;

  TOptionForm = class(TForm)
    GroupBox1: TGroupBox;
    DelphiCheckBox: TCheckBox;
    BcbCheckBox: TCheckBox;
    VbCheckBox: TCheckBox;
    OkButton: TButton;
    CancelButton: TButton;
    ShowFirstCheckBox: TCheckBox;
    procedure CancelButtonClick(Sender: TObject);
    procedure OkButtonClick(Sender: TObject);
    procedure FormCreate(Sender: TObject);
  private
    { Private declarations }
    procedure ReadControl(var Opt: TOptions);
    procedure WriteControl(Opt: TOptions);
    procedure ConnectPrj;
  public
    { Public declarations }
  end;

var
  Options: TOptions;

procedure ShowOptionForm;
procedure LoadOptions;
procedure SaveOptions;
procedure SetDefaultOptions;

implementation

uses Misc, MainFrm;

{$R *.DFM}

procedure ShowOptionForm;
var
  Frm: TOptionForm;
begin
  Frm := TOptionForm.Create(nil);
  Frm.ShowModal;
  Frm.Free;
end;

procedure LoadOptions;
var
  IniFile: TIniFile;
  FileName: string;
  Section: string;
begin
  FileName := GetIniFileName;
  IniFile := TIniFile.Create(FileName);
  Section := 'Options';
  SetDefaultOptions;
  try
    Options.ShowWizardFirstPage := StrToBoolean(IniFile.ReadString(Section, 'ShowWizardFirstPage', 'True'));
    Options.DelphiPrj := StrToBoolean(IniFile.ReadString(Section, 'DelphiPrj', 'True'));
    Options.BcbPrj := StrToBoolean(IniFile.ReadString(Section, 'BcbPrj', 'True'));
    Options.VbPrj := StrToBoolean(IniFile.ReadString(Section, 'VbPrj', 'True'));
  except
  end;
  IniFile.Free;
end;

procedure SaveOptions;
var
  IniFile: TIniFile;
  FileName: string;
  Section: string;
begin
  FileName := GetIniFileName;
  IniFile := TIniFile.Create(FileName);
  Section := 'Options';
  try
    IniFile.WriteString(Section, 'ShowWizardFirstPage', BooleanToStr(Options.ShowWizardFirstPage));
    IniFile.WriteString(Section, 'DelphiPrj', BooleanToStr(Options.DelphiPrj));
    IniFile.WriteString(Section, 'BcbPrj', BooleanToStr(Options.BcbPrj));
    IniFile.WriteString(Section, 'VbPrj', BooleanToStr(Options.VbPrj));
  except
  end;
  IniFile.Free;
end;

procedure SetDefaultOptions;
begin
  with Options do
  begin
    ShowWizardFirstPage := true;
    DelphiPrj := false;
    BcbPrj := false;
    VbPrj := false;
  end;
end;

procedure TOptionForm.ReadControl(var Opt: TOptions);
begin
  Opt.ShowWizardFirstPage := ShowFirstCheckBox.Checked;
  Opt.DelphiPrj := DelphiCheckBox.Checked;
  Opt.BcbPrj := BcbCheckBox.Checked;
  Opt.VbPrj := VbCheckBox.Checked;
end;

procedure TOptionForm.WriteControl(Opt: TOptions);
begin
  ShowFirstCheckBox.Checked := Opt.ShowWizardFirstPage;
  DelphiCheckBox.Checked := Opt.DelphiPrj;
  BcbCheckBox.Checked := Opt.BcbPrj;
  VbCheckBox.Checked := Opt.VbPrj;
end;

procedure TOptionForm.ConnectPrj;
var
  R: TRegistry;
  S: string;
begin
  R := TRegistry.Create;
  R.RootKey := HKEY_CLASSES_ROOT;

  R.OpenKey('\.dpr', true);
  S := R.ReadString('');
  if Options.DelphiPrj then
  begin
    R.OpenKey('\' + S + '\shell\Open with LineCounter\Command', true);
    R.WriteString('', Application.ExeName + ' "%1"');
  end else
    R.DeleteKey('\' + S + '\shell\Open with LineCounter');

  R.OpenKey('\.bpr', true);
  S := R.ReadString('');
  if Options.BcbPrj then
  begin
    R.OpenKey('\' + S + '\shell\Open with LineCounter\Command', true);
    R.WriteString('', Application.ExeName + ' "%1"');
  end else
    R.DeleteKey('\' + S + '\shell\Open with LineCounter');

  R.OpenKey('\.vbp', true);
  S := R.ReadString('');
  if Options.VbPrj then
  begin
    R.OpenKey('\' + S + '\shell\Open with LineCounter\Command', true);
    R.WriteString('', Application.ExeName + ' "%1"');
  end else
    R.DeleteKey('\' + S + '\shell\Open with LineCounter');

  R.Free;
end;


procedure TOptionForm.CancelButtonClick(Sender: TObject);
begin
  ModalResult := mrCancel;
end;

procedure TOptionForm.OkButtonClick(Sender: TObject);
begin
  ReadControl(Options);
  ConnectPrj;
  SaveOptions;
  MainForm.NotShowFirstCheckBox.Checked := not Options.ShowWizardFirstPage;
  ModalResult := mrOk;
end;

procedure TOptionForm.FormCreate(Sender: TObject);
begin
  WriteControl(Options);
end;

end.

⌨️ 快捷键说明

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