📄 oleregister.pas
字号:
//===================== DRAG AND DROP UTILITIES ================================
//
// This unit provides registration for all of the non-visual OLE and UI OLE
// components. Also provides many component and property editors that work
// with these components.
//
// Grahame Marsh
// Freeware for UNDU - you get it for free I make no promises
// gsmarsh@aol.com
//------------------------------------------------------------------------------
unit OleRegister;
interface
uses
Windows, SysUtils, Classes, Controls, Dialogs, Forms, ActiveX, DsgnIntf,
OleConsts, OleDlgs, OleDnD, OleFilters, OleHelpers, OleDataObject, OleDragSource,
OleStd, OleContainer, OleRE;
type
TOleDialogEditor = class (TComponentEditor)
public
procedure ExecuteVerb (index : Integer); override;
function GetVerb (Index : integer): string; override;
function GetVerbCount : integer; override;
procedure Edit; reintroduce; virtual; abstract;
procedure Test; virtual; abstract;
end;
TOleNoTestDialogEditor = class (TOleDialogEditor)
public
function GetVerbCount : integer; override;
end;
TOleBusyDialogEditor = class (TOleDialogEditor)
public
procedure Edit; override;
procedure Test; override;
end;
TOlePasteSpecialDialogEditor = class (TOleDialogEditor)
public
procedure Edit; override;
procedure Test; override;
end;
TOleChangeIconDialogEditor = class (TOleDialogEditor)
public
procedure Edit; override;
procedure Test; override;
end;
TOleInsertObjectDialogEditor = class (TOleDialogEditor)
public
procedure Edit; override;
procedure Test; override;
end;
TOlePropsDialogEditor = class (TOleNoTestDialogEditor)
public
procedure Edit; override;
end;
TOleConvertDialogEditor = class (TOleDialogEditor)
public
procedure Edit; override;
procedure Test; override;
end;
TOleEditLinksDialogEditor = class (TOleNoTestDialogEditor)
public
procedure Edit; override;
end;
TOleChangeSourceDialogEditor = class (TOleNoTestDialogEditor)
public
procedure Edit; override;
end;
TOlePromptUserDialogEditor = class (TOleDialogEditor)
public
procedure Edit; override;
procedure Test; override;
function GetVerbCount : integer; override;
end;
procedure Register;
implementation
uses
OleRegister1, OleRegister2, OleRegister4, OleRegister5, OleRegister6, OleRegister7,
OleRegister9, OleRegister10, OleRegister11, OleRegister12;
//=== OleContainer Component editor ============================================
// Because the number of items that can be added to the popup menu varies wildly,
// the poup action verbs are mapped into an array which then is used to look up the
// action required. Also must allow for the ole object to have verbs of its own,
// which will appear at the top of the popup if present.
type
TContEdit = (ceDivider, ceInsertObject, ceCopyObject, ceDeleteObject,
ceObjectProps, ceEditLink, ceUpdateLink, ceChangeIcon, ceChangeSource,
cePaste, ceClose, cePasteSpecial, ceConvert);
const
CEStrs : array [TContEdit] of string = ('-', 'Insert object...',
'Copy object', 'Delete object', 'Object properties...', 'Edit link...',
'Update link', 'Change icon...', 'Change source...', 'Paste',
'Close', 'Paste special...', 'Convert...');
type
TOleContainerEditor = class (TComponentEditor)
private
Map : array [0..20] of TContEdit;
public
procedure ExecuteVerb (index : Integer); override;
function GetVerb (Index : integer): string; override;
function GetVerbCount : integer; override;
procedure Edit; override;
end;
procedure TOleContainerEditor.ExecuteVerb (Index: Integer);
begin
with TOle2Container (Component) do
try
if not Empty and (Index < ObjectVerbs.Count) then
DoVerb (Index)
else
case Map [Index] of
ceDivider : ; // do nothing
ceInsertObject : begin
InsertObjectDialog;
Close
end;
ceCopyObject : Copy;
ceDeleteObject : DestroyObject;
ceObjectProps : ObjectPropertiesDialog;
ceEditLink : EditLinksDialog;
ceUpdateLink : UpdateLink;
ceChangeIcon : ChangeIconDialog;
ceChangeSource : ChangeSourceDialog;
cePaste : Paste;
cePasteSpecial : PasteSpecialDialog;
ceClose : Close;
ceConvert : ConvertObjectDialog;
end
except
end
end;
function TOleContainerEditor.GetVerb(Index: Integer): String;
begin
with TOle2Container (Component) do
if not Empty and (Index < ObjectVerbs.Count) then
Result := ObjectVerbs [Index]
else
Result := CEStrs [Map [Index]]
end;
function TOleContainerEditor.GetVerbCount: Integer;
procedure AddToMap (N : TContEdit); overload;
begin
Map [Result] := N;
inc (Result)
end;
procedure AddToMap (const N : array of TContEdit); overload;
var
I : integer;
begin
for I := low (N) to high (N) do
AddToMap (N[I])
end;
begin
FillChar (Map, sizeof (Map), $ff);
Result := 0;
// The order with which the map fields are added will set the order in
// the popup menu. I've put the in alpha order.
with TOle2Container (Component) do
case State of
osEmpty : begin
if Assigned (OleInsertObjectDialog) then
AddToMap (ceInsertObject);
if CanPaste then
begin
AddToMap (cePaste);
if Assigned (OlePasteSpecialDialog) then
AddToMap (cePasteSpecial)
end
end;
osOpen,
osRunning : AddToMap (ceClose); // only this on a running or open object
else
Result := ObjectVerbs.Count;
if Result <> 0 then // if there's verbs put in a divider line
AddToMap (ceDivider);
if Assigned (OleChangeIconDialog) and Iconic then
AddToMap (ceChangeIcon);
if Assigned (OleChangeSourceDialog) and Linked then
AddToMap (ceChangeSource);
AddToMap (ceConvert); //@@ conditionals?
AddToMap ([ceCopyObject, ceDeleteObject]);
if Assigned (OleEditLinksDialog) and Linked then
AddToMap (ceEditLink);
if Assigned (OleInsertObjectDialog) then
AddToMap (ceInsertObject);
if Assigned (OleObjectPropsDialog) then
AddToMap (ceObjectProps);
if CanPaste then
begin
AddToMap (cePaste);
if Assigned (OlePasteSpecialDialog) then
AddToMap (cePasteSpecial)
end;
if Assigned (OleUpdateLinksDialog) and Linked then
AddToMap (ceUpdateLink)
end
end;
procedure TOleContainerEditor.Edit;
begin
ExecuteVerb (0)
end;
//=== OleDialogEditor ==========================================================
procedure TOleDialogEditor.ExecuteVerb (Index: Integer);
begin
case Index of
0 : Edit;
1 : Test
end
end;
function TOleDialogEditor.GetVerb(Index: Integer): String;
begin
case Index of
0 : Result := 'Edit Dialog';
1 : Result := 'Test Dialog'
end
end;
function TOleDialogEditor.GetVerbCount: Integer;
begin
with TOleBaseDialog (Component) do
// if the dialog contains custom resource it can't be tested
if Resource = '' then
Result := 2
else
Result := 1
end;
function TOleNoTestDialogEditor.GetVerbCount: integer;
begin
Result := 1
end;
//=== OlePasteSpecialDialogEditor ==============================================
// See OleRegister2 and OleRegister3
procedure TOlePasteSpecialDialogEditor.Edit;
var
PSForm : TOlePasteSpecialForm;
begin
PSForm := TOlePasteSpecialForm.Create (Application);
try
PSForm.Dialog := Component;
PSForm.Initialise;
if PSForm.ShowModal = mrOk then
begin
PSForm.Finalise;
Designer.Modified
end
finally
PSForm.Free
end
end;
procedure TOlePasteSpecialDialogEditor.Test;
begin
with TOlePasteSpecialDialog(Component) do
begin
DataObject := nil;
try
Execute
finally
DataObject := nil
end
end
end;
//=== OleBusyDialogEditor ======================================================
// See OleRegister1
procedure TOleBusyDialogEditor.Edit;
var
BusyForm : TOleBusyForm;
begin
BusyForm := TOleBusyForm.Create (Application);
try
BusyForm.BusyEx := Component is TOleBusyDialogEx;
BusyForm.Dialog := Component;
BusyForm.Initialise;
if BusyForm.ShowModal = mrOk then
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -