Creating a source for recording from Delphi

Is it possible to make the source code (for example, .pas and .dfm) read-only from the Delphi IDE? The right-click option for creating Readonly / Writable files in the IDE does not change the properties of the file system. Is there an IDE extension or the like that can achieve this?

A way to do this without having to integrate a version control system would be preferable. I am using Delphi XE and Delphi 6.

Thanks!

SSE

+7
source share
3 answers

This is how I do it.

Create a new package that will be installed in the development environment in development mode. If you have an existing package, you can continue to use it. Make sure the package requires the designide package. You can do this in the project manager, or simply by looking at the source of the project and adding designide to the requires clause.

Now add the following block to your package.

 unit MakeEditable; interface procedure Register; implementation uses Windows, SysUtils, Menus, ToolsAPI; type TMakeEditable = class(TObject) private FEditorServices: IOTAEditorServices; FFileMenu: TMenuItem; FMakeEditable: TMenuItem; function MenuItemWithCaptionLike(const Menu: TMenuItem; const DesiredCaption: string): TMenuItem; procedure MakeEditableClick(Sender: TObject); public constructor Create; destructor Destroy; override; end; constructor TMakeEditable.Create; var Index: Integer; PreviousMenuItem: TMenuItem; begin inherited; FEditorServices := (BorlandIDEServices as IOTAEditorServices); FFileMenu := MenuItemWithCaptionLike((BorlandIDEServices as INTAServices40).MainMenu.Items, 'File'); if Assigned(FFileMenu) then begin PreviousMenuItem := MenuItemWithCaptionLike(FFileMenu, 'Reopen'); if Assigned(PreviousMenuItem) then begin Index := PreviousMenuItem.MenuIndex; if Index>=0 then begin FMakeEditable := TMenuItem.Create(FFileMenu); FMakeEditable.Caption := 'Ma&ke Editable'; FMakeEditable.OnClick := MakeEditableClick; FFileMenu.Insert(Index, FMakeEditable); end; end; end; end; destructor TMakeEditable.Destroy; begin FMakeEditable.Free; inherited; end; function TMakeEditable.MenuItemWithCaptionLike(const Menu: TMenuItem; const DesiredCaption: string): TMenuItem; var i: Integer; Target, Found: string; begin Target := StringReplace(LowerCase(Trim(DesiredCaption)), '&', '', [rfReplaceAll, rfIgnoreCase]); for i := 0 to Menu.Count-1 do begin Result := Menu.Items[i]; Found := StringReplace(LowerCase(Trim(Result.Caption)), '&', '', [rfReplaceAll, rfIgnoreCase]); if Pos(Target, Found)>0 then begin exit; end; end; Result := nil; end; procedure TMakeEditable.MakeEditableClick(Sender: TObject); procedure MakeFileEditable(const FileName: string); var Attributes: DWORD; begin Attributes := GetFileAttributes(PChar(FileName)); SetFileAttributes(PChar(FileName), Attributes and not FILE_ATTRIBUTE_READONLY); end; var FileName: string; FileExt: string; LinkedFileName: string; EditBuffer: IOTAEditBuffer; begin EditBuffer := FEditorServices.TopBuffer; FileName := EditBuffer.FileName; if FileExists(FileName) then begin MakeFileEditable(FileName); EditBuffer.IsReadOnly := False; FileExt := ExtractFileExt(FileName); if SameText(FileExt,'.dfm') then begin LinkedFileName := ChangeFileExt(FileName, '.pas'); end else if SameText(FileExt,'.pas') then begin LinkedFileName := ChangeFileExt(FileName, '.dfm'); end else begin LinkedFileName := ''; end; if (LinkedFileName<>'') and FileExists(LinkedFileName) then begin MakeFileEditable(LinkedFileName); end; end; end; var MakeEditableInstance: TMakeEditable; procedure Register; begin MakeEditableInstance := TMakeEditable.Create; end; initialization finalization MakeEditableInstance.Free; end. 

When you compile and install this package, you will now have a new menu item in the File menu, which clears the read-only flag in the input buffer and makes the file writable.

enter image description here

+8
source

You can call the .bat file from the tool menu. So you can write a .bat file to do the job for you, and name it with $ EDNAME as a parameter. Your .bat file should see the file name as% 1. Then you need a little logic to change the read-only flag (attrib command?), And then see if there is a .dfm file and do it.

You can also (explicitly) make a Delphi command-line application for this if you don't like .bat files.

This idea, inspired by this article, talks about how to use a .bat file to integrate SVN commands with the Delphi tool menu: http://delphi.wikia.com/wiki/Adding_TortoiseSVN_to_the_Tools_menu

+3
source

Another idea: just add an option to the tool menu: "open the command line here." It allows you to do all kinds of things from the command line, for example, run the attrib command.

Add a new entry to the Tools menu and use the following settings:

 Title: Open Command Prompt Here Program: cmd.exe Working Dir (leave blank) Parameters: cd $PATH($EDNAME) 

Also make a note "Open folder here":

 Title: Open Folder Here Program: explorer.exe Working Dir (leave blank) Parameters: $PATH($EDNAME) 
0
source

All Articles