Delphi 如何在IDE中管理不断变化的项目运行时参数?

Delphi 如何在IDE中管理不断变化的项目运行时参数?,delphi,ide,delphi-xe2,Delphi,Ide,Delphi Xe2,在我的(XE2)IDE中,我必须经常切换项目选项/调试器/参数的设置,因为我正在测试不同的客户端配置、数据库等 “参数”下拉列表变得无法管理。因为它们也没有描述,所以很难确定要删除哪些() 管理这些方面有什么明智的想法吗? 用一个理想的话来说,我想给他们一个标签/描述,对他们重新排序,删除一些…不理想,但解决办法是添加一个冗余的标签参数作为第一个参数 这样,当您使用下拉列表时,您至少可以知道您使用的参数组合。此外,我还为自己的问题添加了一个答案 我已经开始在运行时参数的开头使用[identifi

在我的(XE2)IDE中,我必须经常切换
项目选项/调试器/参数的设置,因为我正在测试不同的客户端配置、数据库等

“参数”下拉列表变得无法管理。因为它们也没有描述,所以很难确定要删除哪些()

管理这些方面有什么明智的想法吗?

用一个理想的话来说,我想给他们一个标签/描述,对他们重新排序,删除一些…

不理想,但解决办法是添加一个冗余的标签参数作为第一个参数

这样,当您使用下拉列表时,您至少可以知道您使用的参数组合。

此外,我还为自己的问题添加了一个答案

我已经开始在运行时参数的开头使用[identifier],我可以在那里输入我想要的内容。此外,我还编写了一个小应用程序,可以清理注册表中存储的参数(位于
HKEY\U CURRENT\U USER\Software\Embarcadero\BDS\9.0\History list\hlRunParameters

下面是Win32应用程序的代码。它将允许您删除和排序注册表值。它是用delphixe2编写的。只需创建一个新的VCL项目并将其用作主窗体

nucleanideparams.pas

unit uCleanIDEParams;
// https://stackoverflow.com/questions/27502689/how-to-manage-constantly-changing-project-run-time-parameters-in-the-ide
// All 32 bit stuff, the Delphi IDE is 32 bit too

interface

uses
  Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants, System.Classes, Vcl.Graphics,
  Vcl.Controls, Vcl.Forms, Vcl.Dialogs, Vcl.StdCtrls, Vcl.CheckLst, Registry,
  Vcl.ExtCtrls;

type
  TFrmCleanIDEParams = class(TForm)
    PnlTop: TPanel;
    BtnLoad: TButton;
    EdtRegKey: TEdit;
    Label1: TLabel;
    ChkRedundant: TCheckBox;
    PnlBottom: TPanel;
    GBxSelection: TGroupBox;
    BtnSelectAll: TButton;
    BtnSelectNone: TButton;
    BtnStartWith: TButton;
    ChkNot: TCheckBox;
    EdtStartWith: TEdit;
    BtnInvert: TButton;
    Label2: TLabel;
    BtnWrite: TButton;
    ChkSort: TCheckBox;
    PnlCenter: TPanel;
    CLBParams: TCheckListBox;
    procedure BtnLoadClick(Sender: TObject);
    procedure BtnSelectAllClick(Sender: TObject);
    procedure BtnSelectNoneClick(Sender: TObject);
    procedure BtnInvertClick(Sender: TObject);
    procedure BtnStartWithClick(Sender: TObject);
    procedure BtnWriteClick(Sender: TObject);
  private
  public
  end;

var
  FrmCleanIDEParams: TFrmCleanIDEParams;

implementation

{$R *.dfm}

procedure TFrmCleanIDEParams.BtnInvertClick(Sender: TObject);
var i: integer;
begin
  for i := 0 to CLBParams.Items.Count-1 do CLBParams.Checked[i] := not CLBParams.Checked[i];
end;

procedure TFrmCleanIDEParams.BtnLoadClick(Sender: TObject);
var
  lReg      : TRegistry;
  lValue,
  lItem,
  lKey      : String;
  i,
  lNrRegVals: Integer;
begin
  lKey := Trim(EdtRegKey.Text);
  if lKey = '' then Exit;
  if lKey[1] = '\' then lKey := Copy(lKey,2);

  lReg := TRegistry.Create(KEY_READ);
  lReg.RootKey := HKEY_CURRENT_USER;

  if not lReg.OpenKey(lKey,false) then
    begin
      MessageDlg('Key not found', mtError, mbOKCancel, 0);
      Exit;
    end;
  if not lReg.ValueExists('Count') then
    begin
      MessageDlg('Value ''Count'' not found', mtError, mbOKCancel, 0);
      Exit;
    end;
  lNrRegVals := lReg.ReadInteger('Count');
  for i := 0 to lNrRegVals-1 do
  begin
     lValue := 'Item' + IntToStr(i);
     if lReg.ValueExists(lValue) then
     begin
       lItem := lReg.ReadString(lValue);
       if ChkRedundant.Checked then
         lItem := Trim(StringReplace(lItem,'  ',' ',[rfReplaceAll]));
       CLBParams.Items.Add(lItem);
     end;
  end;
end;

procedure TFrmCleanIDEParams.BtnSelectAllClick(Sender: TObject);
var i: integer;
begin
  for i := 0 to CLBParams.Items.Count-1 do CLBParams.Checked[i] := true;
end;

procedure TFrmCleanIDEParams.BtnSelectNoneClick(Sender: TObject);
var i: integer;
begin
  for i := 0 to CLBParams.Items.Count-1 do CLBParams.Checked[i] := true;
end;

procedure TFrmCleanIDEParams.BtnStartWithClick(Sender: TObject);
var
  i     : integer;
  lStart,
  lItem : string;
begin
  lStart := Lowercase(Trim(EdtStartWith.Text));
  if lStart = '' then Exit;
  for i := 0 to CLBParams.Items.Count-1 do
  begin
    lItem := lowercase(CLBParams.Items[i]);
    if (not ChkNot.Checked) and (Pos(lStart,lItem) = 1)
    or (ChkNot.Checked) and (Pos(lStart,lItem) <> 1) then
      CLBParams.Checked[i] := true;
  end;
end;

procedure TFrmCleanIDEParams.BtnWriteClick(Sender: TObject);
var
  lReg      : TRegistry;
  lValue,
  lKey      : String;
  i,
  lNrToWrite,
  lNrRegVals: Integer;
begin
  for i := CLBParams.Items.Count-1 downto 0 do
    if not CLBParams.Checked[i] then
      CLBParams.Items.Delete(i);
  if CLBParams.Items.Count = 0 then
    begin
      MessageDlg('Nothing to do', mtInformation, mbOKCancel, 0);
      Exit;
    end;
  if ChkSort.Checked then
    CLBParams.Sorted := true;

  // Now writing back

  lKey := Trim(EdtRegKey.Text);
  if lKey = '' then Exit;
  if lKey[1] = '\' then lKey := Copy(lKey,2);

  lReg := TRegistry.Create(KEY_READ or KEY_WRITE);
  lReg.RootKey := HKEY_CURRENT_USER;
  if not lReg.OpenKey(lKey,false) then
    begin
      MessageDlg('Key not found', mtError, mbOKCancel, 0);
      Exit;
    end;
  if not lReg.ValueExists('Count') then
    begin
      MessageDlg('Value ''Count'' not found', mtError, mbOKCancel, 0);
      Exit;
    end;
  lNrRegVals := lReg.ReadInteger('Count');

  lNrToWrite := CLBParams.Items.Count;
  lReg.WriteInteger('Count',lNrToWrite);
  // Write TCheckListBox items:
  for i := 0 to lNrToWrite-1 do
  begin
    lValue := 'Item' + IntToStr(i);
    lReg.WriteString(lValue,CLBParams.Items[i]);
  end;
  // Remove the rest:
  for i := lNrToWrite to lNrRegVals-1 do
    lReg.DeleteValue('Item' + IntToStr(i));
end;

end.
注:

  • 如果您使用的不是XE2,请不要忘记更改密钥中的版本号。对于旧的Delphi版本,您甚至可能需要将Embarcadero更改为Borland

  • 不要从IDE中运行此应用程序。当它关闭时,Delphi将覆盖您对该注册表项所做的任何更改,它看起来像您的;=)


  • 这很聪明。我可以在那里写任何东西,因为应用程序只查找特定参数。我将在开始时使用[string]进行“标识”,当(?)我还有时间时,编写一个小实用程序来清理注册表字符串列表。
    object FrmCleanIDEParams: TFrmCleanIDEParams
      Left = 0
      Top = 0
      Caption = 'Clean Delphi IDE runtime parameters'
      ClientHeight = 560
      ClientWidth = 549
      Color = clBtnFace
      Font.Charset = DEFAULT_CHARSET
      Font.Color = clWindowText
      Font.Height = -11
      Font.Name = 'Tahoma'
      Font.Style = []
      OldCreateOrder = False
      Position = poScreenCenter
      PixelsPerInch = 96
      TextHeight = 13
      object PnlTop: TPanel
        Left = 0
        Top = 0
        Width = 549
        Height = 58
        Align = alTop
        BevelOuter = bvNone
        TabOrder = 0
        object Label1: TLabel
          Left = 19
          Top = 11
          Width = 308
          Height = 13
          Caption = 'HKEY_CURRENT_USER registry key for IDE runtime parameters:'
        end
        object BtnLoad: TButton
          Left = 496
          Top = 30
          Width = 40
          Height = 25
          Caption = 'Load'
          TabOrder = 0
          OnClick = BtnLoadClick
        end
        object EdtRegKey: TEdit
          Left = 16
          Top = 32
          Width = 473
          Height = 21
          TabOrder = 1
          Text = '\Software\Embarcadero\BDS\9.0\History Lists\hlRunParameters'
        end
        object ChkRedundant: TCheckBox
          Left = 388
          Top = 10
          Width = 151
          Height = 17
          Hint = 'Removes leading, trailing, and duplicate spaces'
          Caption = 'Remove redundant spaces'
          Checked = True
          State = cbChecked
          TabOrder = 2
        end
      end
      object PnlBottom: TPanel
        Left = 0
        Top = 471
        Width = 549
        Height = 89
        Align = alBottom
        BevelOuter = bvNone
        TabOrder = 1
        object Label2: TLabel
          Left = 74
          Top = 62
          Width = 287
          Height = 13
          Caption = 'Click button to write the selected items back to the registry:'
        end
        object GBxSelection: TGroupBox
          Left = 16
          Top = -3
          Width = 520
          Height = 51
          Caption = ' Select '
          TabOrder = 0
          object BtnSelectAll: TButton
            Left = 348
            Top = 18
            Width = 50
            Height = 25
            Caption = 'All'
            Font.Charset = DEFAULT_CHARSET
            Font.Color = clWindowText
            Font.Height = -11
            Font.Name = 'Tahoma'
            Font.Style = []
            ParentFont = False
            TabOrder = 0
            OnClick = BtnSelectAllClick
          end
          object BtnSelectNone: TButton
            Left = 404
            Top = 18
            Width = 50
            Height = 25
            Caption = 'None'
            Font.Charset = DEFAULT_CHARSET
            Font.Color = clWindowText
            Font.Height = -11
            Font.Name = 'Tahoma'
            Font.Style = []
            ParentFont = False
            TabOrder = 1
            OnClick = BtnSelectNoneClick
          end
          object BtnStartWith: TButton
            Left = 51
            Top = 18
            Width = 79
            Height = 25
            Hint = 'Selection is additive'
            Caption = 'starting with:'
            Font.Charset = DEFAULT_CHARSET
            Font.Color = clWindowText
            Font.Height = -11
            Font.Name = 'Tahoma'
            Font.Style = []
            ParentFont = False
            ParentShowHint = False
            ShowHint = True
            TabOrder = 2
            OnClick = BtnStartWithClick
          end
          object ChkNot: TCheckBox
            Left = 11
            Top = 22
            Width = 40
            Height = 17
            Caption = 'NOT'
            TabOrder = 3
          end
          object EdtStartWith: TEdit
            Left = 136
            Top = 20
            Width = 121
            Height = 21
            Hint = 'Case insensitive match'
            ParentShowHint = False
            ShowHint = True
            TabOrder = 4
            Text = '['
          end
          object BtnInvert: TButton
            Left = 460
            Top = 18
            Width = 50
            Height = 25
            Caption = 'Invert'
            Font.Charset = DEFAULT_CHARSET
            Font.Color = clWindowText
            Font.Height = -11
            Font.Name = 'Tahoma'
            Font.Style = []
            ParentFont = False
            TabOrder = 5
            OnClick = BtnInvertClick
          end
        end
        object BtnWrite: TButton
          Left = 364
          Top = 58
          Width = 89
          Height = 25
          Hint = 'Write the selected items back to the registry'
          Caption = 'Write back'
          Font.Charset = DEFAULT_CHARSET
          Font.Color = clWindowText
          Font.Height = -11
          Font.Name = 'Tahoma'
          Font.Style = [fsBold]
          ParentFont = False
          ParentShowHint = False
          ShowHint = True
          TabOrder = 1
          OnClick = BtnWriteClick
        end
        object ChkSort: TCheckBox
          Left = 459
          Top = 62
          Width = 57
          Height = 17
          Caption = '(sorted)'
          Checked = True
          State = cbChecked
          TabOrder = 2
        end
      end
      object PnlCenter: TPanel
        Left = 0
        Top = 58
        Width = 549
        Height = 413
        Align = alClient
        BevelOuter = bvNone
        TabOrder = 2
        object CLBParams: TCheckListBox
          AlignWithMargins = True
          Left = 15
          Top = 10
          Width = 522
          Height = 393
          Margins.Left = 15
          Margins.Top = 10
          Margins.Right = 12
          Margins.Bottom = 10
          Align = alClient
          ItemHeight = 13
          TabOrder = 0
        end
      end
    end