Note that there are some explanatory texts on larger screens.

plurals
  1. POHow to hook a method to the Edit event in Delphi 7 IDE?
    primarykey
    data
    text
    <p>I'd like to automatically checkout a file when I start to edit it in <strong>Delphi 7</strong> IDE. </p> <p>ClearCase is my version control system and I really hate the need to checkout a file before starting to edit. It always breaks my thought flow: I'm trying to solve a problem, find where I need to change, try to edit it, fail because the file is read only, open clearcase, search the file, finally checkout, try to edit the file again, fail because the IDE still thinks it is readonly, tell the IDE that isn't readonly. When I finally go back to code, I forgot what I was trying do do. </p> <p>I've found <a href="http://cc.embarcadero.com/item/21664" rel="nofollow">this nice and simple ClearCase IDE integration code</a>. It works, but uses the deprecated ToolIntf unit. I've added a couple of shortcuts. Here is a <em>simplified version</em> of it (didn't try to compile):</p> <pre><code>unit clearcase; interface uses ToolsApi, ToolIntf; implementation uses Windows, Dialogs, Classes, ExptIntf, Menus, ShellApi, SysUtils; type TDelphiClearcase = class private FClearcaseMenu, FDoCheckOutPasDfm, FDoCheckInPasDfm : TIMenuItemIntf; procedure ExecCommand(const command: string; path: PChar = nil); public destructor Destroy;override; procedure DoClick(Sender: TIMenuItemIntf); property ClearcaseMenu: TIMenuItemIntf read FClearcaseMenu write FClearcaseMenu; property DoCheckOutPasDfm:TIMenuItemIntf write FDoCheckOutPasDfm; property DoCheckInPasDfm: TIMenuItemIntf write FDoCheckInPasDfm; end; var dcc: TDelphiClearcase = nil; { TDelphiClearcase } destructor TDelphiClearcase.Destroy; procedure Remove(item: TIMenuItemIntf); begin if( item = nil )then Exit; item.DestroyMenuItem; FreeAndNil(item); end; begin Remove(FDoCheckOutPasDfm); Remove(FDoCheckInPasDfm); inherited; end; procedure TDelphiClearcase.DoClick(Sender: TIMenuItemIntf); function GetPasDfm(const f: string): string; var aux: string; begin aux := Copy(f, 1, Length(f) - 4); Result := aux + '.pas' + ' ' + aux + '.dfm' end; var command, fileName : string; begin fileName := ToolServices.GetCurrentFile; if( Sender = FDoCheckOutPasDfm )then command := 'cleartool co ' + GetPasDfm(fileName) else if( Sender = FDoCheckInPasDfm )then command := 'cleartool ci ' + GetPasDfm(fileName); ExecCommand(command); ToolServices.ReloadFile(fileName); end; procedure TDelphiClearcase.ExecCommand(const command: string; path: PChar); var pi : TProcessInformation; stinfo : TStartupInfo; begin FillChar(stinfo, SizeOf(stinfo), 0); stinfo.cb := SizeOf(stinfo); if( CreateProcess(nil, PChar(command), nil, nil, True, CREATE_NEW_CONSOLE, nil, path, stinfo, pi) )then begin WaitForSingleObject(pi.hProcess, INFINITE); CloseHandle(pi.hProcess) end end; procedure CreateMenus; var services: TIToolServices; begin if( BorlandIDEServices = nil )then Exit; services := ToolServices; if( services = nil )then Exit; dcc := TDelphiClearcase.Create; dcc.ClearcaseMenu := services.GetMainMenu.GetMenuItems.InsertItem(6, 'C&amp;learcase', 'ClearcaseMenu', 'ClearcaseTools', 0, 0, 0, [mfEnabled, mfVisible], nil); dcc.DoCheckOutPasDfm := dcc.ClearcaseMenu.InsertItem(2, 'Check Out pas and dfm', 'DoCheckOutPasDfm', 'Undo the check outs', ShortCut(Ord('&gt;'), [ssCtrl]), 0, 2, [mfEnabled, mfVisible], dcc.DoClick); dcc.DoCheckInPasDfm:= dcc.ClearcaseMenu.InsertItem(4, 'Check In pas and dfm', 'DoCheckInPasDfm', 'Check in current files', ShortCut(Ord('&lt;'), [ssCtrl]), 0, 2, [mfEnabled, mfVisible], dcc.DoClick); end; procedure DestroyMenus; begin FreeAndNil(dcc); end; initialization CreateMenus; finalization DestroyMenus end. </code></pre> <p>I'd like to checkout the file when I first start editing it and it is read only. I have no idea how to hook a function to the IDE edit event of a file. Any pointers are welcome.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload