Delphi 2007:只保存DSK文件中的断点选项?

时间:2014-12-04 07:46:38

标签: delphi delphi-2007

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

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

1 个答案:

答案 0 :(得分:6)

我从未遇到IDE设施只保存.Dsk文件中与断点相关的设置。

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

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

我在阅读你的q时没有编写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.