📄 associations.pas
字号:
{+------------------------------------------------------------
| Unit Associations
|
| Version: 1.0 Created: 20.03.99
| Last Modified: 20.03.99
| Author : P. Below
| Project: Delphi Demos
| Description:
| Collects routines and classes used to make an application
| a server for a file extension. The application using this
| unit calls the procedures RegisterFiletype, RegisterDDEServer
| and RegisterFileIcon (optional) from the initialization
| section of its main unit. It attaches a handler to the
| DDEServers OnExecuteMacro event via AttachExecuteMacrohandler
| in the main forms OnCreate event handler. The handler will
| be called for macros passed to the ddeServer by Explorer or
| other client applications calling ShellExecute.
| Creating the ddeServer early in the program startup sequence
| makes sure the shell does not get a timeout when it tries to
| establish a DDE conversation to a newly started instance
| of the application.
+------------------------------------------------------------}
Unit Associations;
Interface
Uses DDEMan;
Procedure RegisterFiletype( Const extension, filetype, description,
verb: String; params: String );
Procedure RegisterDDEServer( Const filetype, verb, macro: String );
Procedure RegisterFileIcon( Const filetype, iconsource: String;
iconindex: Cardinal );
Function FiletypeIsRegistered( Const extension, filetype: String ): Boolean;
Procedure AttachExecuteMacrohandler( aHandler: TMacroEvent );
Implementation
Uses Windows, Classes, SysUtils, Registry;
ResourceString
eCannotCreateKey =
'Cannot create key %s, the user account may not have the required '+
'rights to create registry keys under HKEY_CLASSES_ROOT.';
Type
TDDEHandler = Class
private
FDdeServer: TDDEServerConv;
FQueue : TStringlist;
FExecuteMacro: TMacroEvent;
Procedure Macrohandler(Sender: TObject; Msg: TStrings);
Procedure SetExecuteMacro( value: TMacroEvent );
Function GetServername: String;
Procedure DoExecuteMacro;
public
Constructor Create;
Destructor Destroy; override;
property OnExecuteMacro: TMacroEvent
read FExecuteMacro write SetExecuteMacro;
property Name: String
read GetServername;
end; { Class TDDEHandler }
ERegistryError = Class( Exception );
Var
ddeServer: TDDEHandler = Nil;
{+========================
| Methods of TDDEHandler
+=======================}
{+------------------------------------------------------------
| Constructor TDDEHandler.Create
|
| Parameters : none
| Call method: static
| Visibility : public
| Description:
| Creates the macro queue and the TDDeServerConv object to
| receive macro requests. The topic name is 'Macros'.
| Error Conditions: none
| Created: 20.03.99 by P. Below
+------------------------------------------------------------}
Constructor TDDEHandler.Create;
Begin
inherited Create;
FQueue := TStringlist.Create;
FDdeServer:= TDDEServerConv.Create( Nil );
With FDdeServer Do Begin
Name := 'Macros';
OnExecuteMacro := Macrohandler;
End; { With }
End; { TDDEHandler.Create }
{+------------------------------------------------------------
| Destructor TDDEHandler.Destroy
|
| Parameters : none
| Call method: virtual, overriden
| Visibility : public
| Description:
| Destroy the TDDeServerConv object and the macro queue.
| Error Conditions: none
| Created: 20.03.99 by P. Below
+------------------------------------------------------------}
Destructor TDDEHandler.Destroy;
Begin
// FDdeServer.Free;
{ Note: freeing the FDdeServer causes an exception if done from
the finalization section, probably because the ddeMgr has already
disposed of some internal list of his. No great deal, the
ddeMgr will unregister the DDE topic on itself. }
FQueue.Free;
inherited Destroy
End; { TDDEHandler.Destroy }
{+------------------------------------------------------------
| Procedure TDDEHandler.Macrohandler
|
| Parameters :
| Sender: TDDEClientConv that received the macro request
| Msg : the macro strings
| Call method: static
| Visibility : private
| Description:
| This method handles the OnExecuteMacro event of the FDdeServer
| object. A macro has to be a string enclosed in square
| brackets, e.g. '[Open("somefilename")]'. Several macros
| may be concatenated in one request, with no intervening chars,
| e.g. '[Print("somefilename")][Quit()]'. This method will take apart
| such composite requests and store each macro as a separate item
| into the macro queue. It then fires this objects OnExecuteMacro
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -