📄 dsgnintf.pas
字号:
{*******************************************************}
{ }
{ Borland Delphi Visual Component Library }
{ }
{ Copyright (c) 1995,98 Inprise Corporation }
{ }
{*******************************************************}
unit DsgnIntf;
interface
{$N+,S-,R-}
uses Windows, SysUtils, Classes, Graphics, Controls, Forms, TypInfo;
type
IEventInfos = interface
['{11667FF0-7590-11D1-9FBC-0020AF3D82DA}']
function GetCount: Integer;
function GetEventValue(Index: Integer): string;
function GetEventName(Index: Integer): string;
procedure ClearEvent(Index: Integer);
property Count: Integer read GetCount;
end;
IPersistent = interface
['{82330133-65D1-11D1-9FBB-0020AF3D82DA}'] {Java}
procedure DestroyObject;
function Equals(const Other: IPersistent): Boolean;
function GetClassname: string;
function GetEventInfos: IEventInfos;
function GetNamePath: string;
function GetOwner: IPersistent;
function InheritsFrom(const Classname: string): Boolean;
function IsComponent: Boolean; // object is stream createable
function IsControl: Boolean;
function IsWinControl: Boolean;
property Classname: string read GetClassname;
property Owner: IPersistent read GetOwner;
property NamePath: string read GetNamePath;
// property PersistentProps[Index: Integer]: IPersistent
// property PersistentPropCount: Integer;
property EventInfos: IEventInfos read GetEventInfos;
end;
IComponent = interface(IPersistent)
['{B2F6D681-5098-11D1-9FB5-0020AF3D82DA}'] {Java}
function FindComponent(const Name: string): IComponent;
function GetComponentCount: Integer;
function GetComponents(Index: Integer): IComponent;
function GetComponentState: TComponentState;
function GetComponentStyle: TComponentStyle;
function GetDesignInfo: TSmallPoint;
function GetDesignOffset: TPoint;
function GetDesignSize: TPoint;
function GetName: string;
function GetOwner: IComponent;
function GetParent: IComponent;
procedure SetDesignInfo(const Point: TSmallPoint);
procedure SetDesignOffset(const Point: TPoint);
procedure SetDesignSize(const Point: TPoint);
procedure SetName(const Value: string);
property ComponentCount: Integer read GetComponentCount;
property Components[Index: Integer]: IComponent read GetComponents;
property ComponentState: TComponentState read GetComponentState;
property ComponentStyle: TComponentStyle read GetComponentStyle;
property DesignInfo: TSmallPoint read GetDesignInfo write SetDesignInfo;
property DesignOffset: TPoint read GetDesignOffset write SetDesignOffset;
property DesignSize: TPoint read GetDesignSize write SetDesignSize;
property Name: string read GetName write SetName;
property Owner: IComponent read GetOwner;
property Parent: IComponent read GetParent;
end;
IImplementation = interface
['{F9D448F2-50BC-11D1-9FB5-0020AF3D82DA}']
function GetInstance: TObject;
end;
function MakeIPersistent(Instance: TPersistent): IPersistent;
function ExtractPersistent(const Intf: IPersistent): TPersistent;
function TryExtractPersistent(const Intf: IPersistent): TPersistent;
function MakeIComponent(Instance: TComponent): IComponent;
function ExtractComponent(const Intf: IComponent): TComponent;
function TryExtractComponent(const Intf: IComponent): TComponent;
var
MakeIPersistentProc: function (Instance: TPersistent): IPersistent = nil;
MakeIComponentProc: function (Instance: TComponent): IComponent = nil;
type
{ IDesignerSelections }
{ Used to transport the selected objects list in and out of the form designer.
Replaces TComponentList in form designer interface. }
IDesignerSelections = interface
['{82330134-65D1-11D1-9FBB-0020AF3D82DA}'] {Java}
function Add(const Item: IPersistent): Integer;
function Equals(const List: IDesignerSelections): Boolean;
function Get(Index: Integer): IPersistent;
function GetCount: Integer;
property Count: Integer read GetCount;
property Items[Index: Integer]: IPersistent read Get; default;
end;
function CreateSelectionList: IDesignerSelections;
type
TComponentList = class;
IComponentList = interface
['{8ED8AD16-A241-11D1-AA94-00C04FB17A72}']
function GetComponentList: TComponentList;
end;
{ TComponentList }
{ Used to transport VCL component selections between property editors }
TComponentList = class(TInterfacedObject, IDesignerSelections,
IComponentList)
private
FList: TList;
{ IDesignSelections }
function IDesignerSelections.Add = Intf_Add;
function Intf_Add(const Item: IPersistent): Integer;
function IDesignerSelections.Equals = Intf_Equals;
function Intf_Equals(const List: IDesignerSelections): Boolean;
function IDesignerSelections.Get = Intf_Get;
function Intf_Get(Index: Integer): IPersistent;
function Get(Index: Integer): TPersistent;
function GetCount: Integer;
{ IComponentList }
function GetComponentList: TComponentList;
public
constructor Create;
destructor Destroy; override;
function Add(Item: TPersistent): Integer;
function Equals(List: TComponentList): Boolean;
property Count: Integer read GetCount;
property Items[Index: Integer]: TPersistent read Get; default;
end;
{ IFormDesigner }
type
IFormDesigner = interface(IDesigner)
['{ABBE7255-5495-11D1-9FB5-0020AF3D82DA}']
function CreateMethod(const Name: string; TypeData: PTypeData): TMethod;
function GetMethodName(const Method: TMethod): string;
procedure GetMethods(TypeData: PTypeData; Proc: TGetStrProc);
function GetPrivateDirectory: string;
procedure GetSelections(const List: IDesignerSelections);
function MethodExists(const Name: string): Boolean;
procedure RenameMethod(const CurName, NewName: string);
procedure SelectComponent(Instance: TPersistent);
procedure SetSelections(const List: IDesignerSelections);
procedure ShowMethod(const Name: string);
function UniqueName(const BaseName: string): string;
procedure GetComponentNames(TypeData: PTypeData; Proc: TGetStrProc);
function GetComponent(const Name: string): TComponent;
function GetComponentName(Component: TComponent): string;
function GetObject(const Name: string): TPersistent;
function GetObjectName(Instance: TPersistent): string;
procedure GetObjectNames(TypeData: PTypeData; Proc: TGetStrProc);
function MethodFromAncestor(const Method: TMethod): Boolean;
function CreateComponent(ComponentClass: TComponentClass; Parent: TComponent;
Left, Top, Width, Height: Integer): TComponent;
function IsComponentLinkable(Component: TComponent): Boolean;
procedure MakeComponentLinkable(Component: TComponent);
function GetRoot: TComponent;
procedure Revert(Instance: TPersistent; PropInfo: PPropInfo);
function GetIsDormant: Boolean;
function HasInterface: Boolean;
function HasInterfaceMember(const Name: string): Boolean;
procedure AddToInterface(InvKind: Integer; const Name: string; VT: Word;
const TypeInfo: string);
procedure GetProjectModules(Proc: TGetModuleProc);
function GetAncestorDesigner: IFormDesigner;
function IsSourceReadOnly: Boolean;
property IsDormant: Boolean read GetIsDormant;
property AncestorDesigner: IFormDesigner read GetAncestorDesigner;
end;
{ TPropertyEditor
Edits a property of a component, or list of components, selected into the
Object Inspector. The property editor is created based on the type of the
property being edited as determined by the types registered by
RegisterPropertyEditor. The Object Inspector uses the a TPropertyEditor
for all modification to a property. GetName and GetValue are called to display
the name and value of the property. SetValue is called whenever the user
requests to change the value. Edit is called when the user double-clicks the
property in the Object Inspector. GetValues is called when the drop-down
list of a property is displayed. GetProperties is called when the property
is expanded to show sub-properties. AllEqual is called to decide whether or
not to display the value of the property when more than one component is
selected.
The following are methods that can be overriden to change the behavior of
the property editor:
Activate
Called whenever the property becomes selected in the object inspector.
This is potientially useful to allow certian property attributes to
to only be determined whenever the property is selected in the object
inspector. Only paSubProperties and paMultiSelect, returned from
GetAttributes, need to be accurate before this method is called.
AllEqual
Called whenever there are more than one components selected. If this
method returns true, GetValue is called, otherwise blank is displayed
in the Object Inspector. This is called only when GetAttributes
returns paMultiSelect.
AutoFill
Called to determine whether the values returned by GetValues can be
selected incrementally in the Object Inspector. This is called only when
GetAttributes returns paValueList.
Edit
Called when the '...' button is pressed or the property is double-clicked.
This can, for example, bring up a dialog to allow the editing the
component in some more meaningful fashion than by text (e.g. the Font
property).
GetAttributes
Returns the information for use in the Object Inspector to be able to
show the approprate tools. GetAttributes return a set of type
TPropertyAttributes:
paValueList: The property editor can return an enumerated list of
values for the property. If GetValues calls Proc
with values then this attribute should be set. This
will cause the drop-down button to appear to the right
of the property in the Object Inspector.
paSortList: Object Inspector to sort the list returned by
GetValues.
paSubProperties: The property editor has sub-properties that will be
displayed indented and below the current property in
standard outline format. If GetProperties will
generate property objects then this attribute should
be set.
paDialog: Indicates that the Edit method will bring up a
dialog. This will cause the '...' button to be
displayed to the right of the property in the Object
Inspector.
paMultiSelect: Allows the property to be displayed when more than
one component is selected. Some properties are not
approprate for multi-selection (e.g. the Name
property).
paAutoUpdate: Causes the SetValue method to be called on each
change made to the editor instead of after the change
has been approved (e.g. the Caption property).
paReadOnly: Value is not allowed to change.
paRevertable: Allows the property to be reverted to the original
value. Things that shouldn't be reverted are nested
properties (e.g. Fonts) and elements of a composite
property such as set element values.
GetComponent
Returns the Index'th component being edited by this property editor. This
is used to retieve the components. A property editor can only refer to
multiple components when paMultiSelect is returned from GetAttributes.
GetEditLimit
Returns the number of character the user is allowed to enter for the
value. The inplace editor of the object inspector will be have its
text limited set to the return value. By default this limit is 255.
GetName
Returns a the name of the property. By default the value is retrieved
from the type information with all underbars replaced by spaces. This
should only be overriden if the name of the property is not the name
that should appear in the Object Inspector.
GetProperties
Should be overriden to call PropertyProc for every sub-property (or nested
property) of the property begin edited and passing a new TPropertyEdtior
for each sub-property. By default, PropertyProc is not called and no
sub-properties are assumed. TClassProperty will pass a new property
editor for each published property in a class. TSetProperty passes a
new editor for each element in the set.
GetPropType
Returns the type information pointer for the propertie(s) being edited.
GetValue
Returns the string value of the property. By default this returns
'(unknown)'. This should be overriden to return the appropriate value.
GetValues
Called when paValueList is returned in GetAttributes. Should call Proc
for every value that is acceptable for this property. TEnumProperty
will pass every element in the enumeration.
Initialize
Called after the property editor has been created but before it is used.
Many times property editors are created and because they are not a common
property across the entire selection they are thrown away. Initialize is
called after it is determined the property editor is going to be used by
the object inspector and not just thrown away.
SetValue(Value)
Called to set the value of the property. The property editor should be
able to translate the string and call one of the SetXxxValue methods. If
the string is not in the correct format or not an allowed value, the
property editor should generate an exception describing the problem. Set
value can ignore all changes and allow all editing of the property be
accomplished through the Edit method (e.g. the Picture property).
Properties and methods useful in creating a new TPropertyEditor classes:
Name property
Returns the name of the property returned by GetName
PrivateDirectory property
It is either the .EXE or the "working directory" as specified in
the registry under the key:
"HKEY_CURRENT_USER\Software\Borland\Delphi\3.0\Globals\PrivateDir"
If the property editor needs auxilury or state files (templates, examples,
etc) they should be stored in this directory.
Value property
The current value, as a string, of the property as returned by GetValue.
Modified
Called to indicate the value of the property has been modified. Called
automatically by the SetXxxValue methods. If you call a TProperty
SetXxxValue method directly, you *must* call Modified as well.
GetXxxValue
Gets the value of the first property in the Properties property. Calls
the appropriate TProperty GetXxxValue method to retrieve the value.
SetXxxValue
Sets the value of all the properties in the Properties property. Calls
the approprate TProperty SetXxxxValue methods to set the value. }
TPropertyAttribute = (paValueList, paSubProperties, paDialog,
paMultiSelect, paAutoUpdate, paSortList, paReadOnly, paRevertable);
TPropertyAttributes = set of TPropertyAttribute;
TPropertyEditor = class;
TInstProp = record
Instance: TPersistent;
PropInfo: PPropInfo;
end;
PInstPropList = ^TInstPropList;
TInstPropList = array[0..1023] of TInstProp;
TGetPropEditProc = procedure(Prop: TPropertyEditor) of object;
TPropertyEditor = class
private
FDesigner: IFormDesigner;
FPropList: PInstPropList;
FPropCount: Integer;
function GetPrivateDirectory: string;
procedure SetPropEntry(Index: Integer; AInstance: TPersistent;
APropInfo: PPropInfo);
protected
constructor Create(const ADesigner: IFormDesigner; APropCount: Integer);
function GetPropInfo: PPropInfo;
function GetFloatValue: Extended;
function GetFloatValueAt(Index: Integer): Extended;
function GetMethodValue: TMethod;
function GetMethodValueAt(Index: Integer): TMethod;
function GetOrdValue: Longint;
function GetOrdValueAt(Index: Integer): Longint;
function GetStrValue: string;
function GetStrValueAt(Index: Integer): string;
function GetVarValue: Variant;
function GetVarValueAt(Index: Integer): Variant;
procedure Modified;
procedure SetFloatValue(Value: Extended);
procedure SetMethodValue(const Value: TMethod);
procedure SetOrdValue(Value: Longint);
procedure SetStrValue(const Value: string);
procedure SetVarValue(const Value: Variant);
public
destructor Destroy; override;
procedure Activate; virtual;
function AllEqual: Boolean; virtual;
function AutoFill: Boolean; virtual;
procedure Edit; virtual;
function GetAttributes: TPropertyAttributes; virtual;
function GetComponent(Index: Integer): TPersistent;
function GetEditLimit: Integer; virtual;
function GetName: string; virtual;
procedure GetProperties(Proc: TGetPropEditProc); virtual;
function GetPropType: PTypeInfo;
function GetValue: string; virtual;
procedure GetValues(Proc: TGetStrProc); virtual;
procedure Initialize; virtual;
procedure Revert;
procedure SetValue(const Value: string); virtual;
function ValueAvailable: Boolean;
property Designer: IFormDesigner read FDesigner;
property PrivateDirectory: string read GetPrivateDirectory;
property PropCount: Integer read FPropCount;
property Value: string read GetValue write SetValue;
end;
TPropertyEditorClass = class of TPropertyEditor;
{ TOrdinalProperty
The base class of all ordinal property editors. It established that ordinal
properties are all equal if the GetOrdValue all return the same value. }
TOrdinalProperty = class(TPropertyEditor)
function AllEqual: Boolean; override;
function GetEditLimit: Integer; override;
end;
{ TIntegerProperty
Default editor for all Longint properties and all subtypes of the Longint
type (i.e. Integer, Word, 1..10, etc.). Retricts the value entrered into
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -