プロジェクトロード時に「コントロールのロック」を自動でオンにしたい。
したいけどできなかったので作りました。
全ソース
unit LockOnLoad; interface uses ToolsAPI, ComponentDesigner; implementation type TIDENotifier = class(TNotifierObject, IOTAIDENotifier) private procedure FileNotification(NotifyCode: TOTAFileNotification; const FileName: string; var Cancel: Boolean); procedure BeforeCompile(const Project: IOTAProject; var Cancel: Boolean); overload; procedure AfterCompile(Succeeded: Boolean); overload; end; { TIDENotifier } procedure TIDENotifier.AfterCompile(Succeeded: Boolean); begin { Do nothing } end; procedure TIDENotifier.BeforeCompile(const Project: IOTAProject; var Cancel: Boolean); begin { Do nothing } end; procedure TIDENotifier.FileNotification(NotifyCode: TOTAFileNotification; const FileName: string; var Cancel: Boolean); begin if (NotifyCode = ofnProjectDesktopLoad) and (Designers <> nil) then Designers.SetControlsLocked(True); end; var NotifierIndex: Integer; initialization NotifierIndex := (BorlandIDEServices as IOTAServices).AddNotifier(TIDENotifier.Create); finalization (BorlandIDEServices as IOTAServices).RemoveNotifier(NotifierIndex); end.
使い方
適当な既存パッケージ、あるいは新規パッケージに上記ユニットを追加し、パッケージのrequires節に「designide」を書き加えたら、あとはインストールするだけです。
開発とテストはXE4で行いましたが、Open Tools APIを使ってるだけなのでたぶん他の環境でも動くと思われます*1。
*1:イベントの発動をプロジェクトデスクトップのロード時に行ってるので、自動保存にしてない人は動かないかも