德尔福 2007 : save only the breakpoint options in the DSK file?

标签 delphi delphi-2007

是否可以在 Delphi 中只将断点保存在项目的 .DSK 文件中,而不保存其他桌面设置?

大多数 .DSK 都妨碍了,但无法保存调试断点是一个真正的痛苦(尤其是当它们是有条件的或附加了操作时)。

最佳答案

我从未遇到过在 .Dsk 文件中仅保存与断点相关的设置的 IDE 工具。

为了娱乐,我想我会尝试使用 OTA 通知通过 IDE 插件实现一些东西。下面的代码安装到安装在 D7 中的包中运行良好,IDE 似乎很乐意重新打开一个项目,其 .Dsk 文件已由它处理(并且设置了断点!)。

如您所见,当使用 ofnProjectDesktopSave 的 NotifyCode 调用时,它会捕获 OTA 通知程序的 FileNotification 事件,这发生在 IDE 保存 .Dsk 文件(最初扩展名为“.$$$”之后,我失败了第一次写这篇文章时要注意)。然后它读取保存的文件文件,并准备一个更新版本,从中删除除指定部分列表之外的所有部分。然后,用户可以选择将精简后的文件保存回磁盘。我使用 TMemIniFile 来完成大部分处理,只是为了最大限度地减少所需的代码量。

当我阅读您的问题时,我对编写 OTA 通知程序的经验为零,但下面引用的 GE 专家常见问题解答非常有帮助,尤其是示例通知程序代码。

通常情况下,删除项目的 .Dsk 文件是无害的,但请谨慎使用此代码,因为它尚未经过压力测试。

更新: 我注意到 TIdeNotifier.FileNotification 事件收到的文件名实际上有一个扩展名“.$$$”。我不太确定为什么会这样,但似乎在文件重命名为 xxx.Dsk 之前调用了该事件。我认为这需要改变方式 保存精简版,但显然不是。

更新 #2: 使用文件夹监控实用程序查看实际发生的情况后,发现代码收到的桌面保存通知只是与.Dsk 文件。其中包括将任何现有版本的 .Dsk 文件重命名为 .~Dsk 文件,并最终将 .$$$ 文件保存为新的 .Dsk 文件。

unit DskFilesu;

interface

{$define ForDPK}  // undefine to test in regular app

uses
  Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
  Buttons, StdCtrls, IniFiles, TypInfo
{$ifdef ForDPK}
  , ToolsApi
{$endif}
  ;

{$ifdef ForDPK}

{
  Code for OTA TIdeNotifier adapted from, and courtesy of, the link on http://www.gexperts.org/open-tools-api-faq/#idenotifier
}

type
  TIdeNotifier = class(TNotifierObject, IOTANotifier, IOTAIDENotifier)
  protected
    procedure AfterCompile(Succeeded: Boolean);
    procedure BeforeCompile(const Project: IOTAProject; var Cancel: Boolean);
    procedure FileNotification(NotifyCode: TOTAFileNotification;
      const FileName: string; var Cancel: Boolean);
  end;
{$endif}

type
  TDskForm = class(TForm)
    edDskFileName: TEdit;
    SpeedButton1: TSpeedButton;
    OpenDialog1: TOpenDialog;
    lbSectionsToKeep: TListBox;
    lbDskSections: TListBox;
    moDskFile: TMemo;
    btnSave: TButton;
    procedure btnSaveClick(Sender: TObject);
    procedure FormCreate(Sender: TObject);
    procedure SpeedButton1Click(Sender: TObject);
  private
    procedure GetSectionsToKeep;
    function GetDskFileName: String;
    procedure SetDskFileName(const Value: String);
    function GetDskFile: Boolean;
  protected
  public
    DskIni : TMemIniFile;
    property DskFileName : String read GetDskFileName write SetDskFileName;
  end;

var
  NotifierIndex: Integer;
  DskForm: TDskForm;

{$ifdef ForDPK}
procedure Register;
{$endif}

implementation

{$R *.DFM}

{$ifdef ForDPK}
procedure Register;
var
  Services: IOTAServices;
begin
  Services := BorlandIDEServices as IOTAServices;
  Assert(Assigned(Services), 'IOTAServices not available');
  NotifierIndex := Services.AddNotifier(TIdeNotifier.Create);
end;
{$endif}

procedure DskPopUp(FileName : String);
var
  F : TDskForm;
begin
  F := TDskForm.Create(Application);
  try
    F.DskFileName := FileName;
    F.ShowModal;
  finally
    F.Free;
  end;
end;

function TDskForm.GetDskFileName: String;
begin
  Result := edDskFileName.Text;
end;

procedure TDskForm.SetDskFileName(const Value: String);
begin
  edDskFileName.Text := Value;
  if Assigned(DskIni) then
    FreeAndNil(DskIni);
  btnSave.Enabled := False;

  DskIni  := TMemIniFile.Create(DskFileName);
  DskIni.ReadSections(lbDskSections.Items);
  GetSectionsToKeep;
end;

procedure TDskForm.btnSaveClick(Sender: TObject);
begin
  DskIni.UpdateFile;
end;

procedure TDskForm.FormCreate(Sender: TObject);
begin
  lbSectionsToKeep.Items.Add('watches');
  lbSectionsToKeep.Items.Add('breakpoints');
  lbSectionsToKeep.Items.Add('addressbreakpoints');

  if not IsLibrary then
    DskFileName := ChangeFileExt(Application.ExeName, '.Dsk');
end;

procedure TDskForm.GetSectionsToKeep;
var
  i,
  Index : Integer;
  SectionName : String;
begin
  moDskFile.Lines.Clear;
  for i := lbDskSections.Items.Count - 1 downto 0 do begin
    SectionName := lbDskSections.Items[i];
    Index := lbSectionsToKeep.Items.IndexOf(SectionName);
    if Index < 0 then
      DskIni.EraseSection(SectionName);
  end;
  DskIni.GetStrings(moDskFile.Lines);
  btnSave.Enabled := True;
end;

function TDskForm.GetDskFile: Boolean;
begin
  OpenDialog1.FileName := DskFileName;
  Result := OpenDialog1.Execute;
  if Result then
    DskFileName := OpenDialog1.FileName;
end;

procedure TDskForm.SpeedButton1Click(Sender: TObject);
begin
  GetDskFile;
end;

{$ifdef ForDPK}

procedure RemoveNotifier;
var
  Services: IOTAServices;
begin
  if NotifierIndex <> -1 then
  begin
    Services := BorlandIDEServices as IOTAServices;
    Assert(Assigned(Services), 'IOTAServices not available');
    Services.RemoveNotifier(NotifierIndex);
  end;
end;

function MsgServices: IOTAMessageServices;
begin
  Result := (BorlandIDEServices as IOTAMessageServices);
  Assert(Result <> nil, 'IOTAMessageServices not available');
end;

procedure TIdeNotifier.AfterCompile(Succeeded: Boolean);
begin
end;

procedure TIdeNotifier.BeforeCompile(const Project: IOTAProject; var Cancel: Boolean);
begin
  Cancel := False;
end;

procedure TIdeNotifier.FileNotification(NotifyCode: TOTAFileNotification;
  const FileName: string; var Cancel: Boolean);
begin
  Cancel := False;
  // Note: The FileName passed below has an extension of '.$$$'
  if NotifyCode = ofnProjectDesktopSave then
    DskPopup(FileName);
end;

initialization

finalization
  RemoveNotifier;
{$endif}

end.

关于德尔福 2007 : save only the breakpoint options in the DSK file?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27288723/

相关文章:

delphi - 更改行代码上的 Delphi 线程大小

delphi - IntraWeb 的 SSL 问题 - Delphi 2007

delphi - 从函数指针获取函数名?

delphi - 如何使用 Indy TIdTCPServer 跟踪客户端数量

delphi - Delphi调试器显示????货币变量

delphi - OnKeyPress 事件中如何转换 Ctrl + 快捷键?

delphi - 如何让 TAnimate 的通用 AVI 在 Vista 和 Win7 上运行?

delphi - SkypeKit 与使用 Skype API 编程有何不同?

c# - 在 C# 中使用 Delphi DLL

delphi - 如何为整个项目设置 $RTTI 指令?