home *** CD-ROM | disk | FTP | other *** search
/ PC Pro 1999 February / DPPCPRO0299.ISO / February / Delphi / Install / DATA.Z / DSGNINTF.PAS < prev    next >
Encoding:
Pascal/Delphi Source File  |  1996-06-11  |  62.6 KB  |  2,125 lines

  1.  
  2. {*******************************************************}
  3. {                                                       }
  4. {       Delphi Visual Component Library                 }
  5. {                                                       }
  6. {       Copyright (c) 1995,96 Borland International     }
  7. {                                                       }
  8. {*******************************************************}
  9.  
  10. unit DsgnIntf;
  11.  
  12. interface
  13.  
  14. {$N+,S-,R-}
  15.  
  16. uses SysUtils, Classes, Graphics, Controls, Forms, TypInfo;
  17.  
  18. type
  19.  
  20. { TComponentList }
  21.  
  22.   TComponentList = class(TObject)
  23.   private
  24.     FList: TList;
  25.     function Get(Index: Integer): TComponent;
  26.     function GetCount: Integer;
  27.   public
  28.     constructor Create;
  29.     destructor Destroy; override;
  30.     function Add(Item: TComponent): Integer;
  31.     function Equals(List: TComponentList): Boolean;
  32.     property Count: Integer read GetCount;
  33.     property Items[Index: Integer]: TComponent read Get; default;
  34.   end;
  35.  
  36. { TFormDesigner }
  37.  
  38.   TFormDesigner = class(TDesigner)
  39.   public
  40.     function CreateMethod(const Name: string; TypeData: PTypeData): TMethod; virtual; abstract;
  41.     function GetMethodName(const Method: TMethod): string; virtual; abstract;
  42.     procedure GetMethods(TypeData: PTypeData; Proc: TGetStrProc); virtual; abstract;
  43.     function GetPrivateDirectory: string; virtual; abstract;
  44.     procedure GetSelections(List: TComponentList); virtual; abstract;
  45.     function MethodExists(const Name: string): Boolean; virtual; abstract;
  46.     procedure RenameMethod(const CurName, NewName: string); virtual; abstract;
  47.     procedure SelectComponent(Component: TComponent); virtual; abstract;
  48.     procedure SetSelections(List: TComponentList); virtual; abstract;
  49.     procedure ShowMethod(const Name: string); virtual; abstract;
  50.     function UniqueName(const BaseName: string): string; virtual; abstract;
  51.     procedure GetComponentNames(TypeData: PTypeData; Proc: TGetStrProc); virtual; abstract;
  52.     function GetComponent(const Name: string): TComponent; virtual; abstract;
  53.     function GetComponentName(Component: TComponent): string; virtual; abstract;
  54.     function MethodFromAncestor(const Method: TMethod): Boolean; virtual; abstract;
  55.     function CreateComponent(ComponentClass: TComponentClass; Parent: TComponent;
  56.       Left, Top, Width, Height: Integer): TComponent; virtual; abstract;
  57.     function IsComponentLinkable(Component: TComponent): Boolean; virtual; abstract;
  58.     procedure MakeComponentLinkable(Component: TComponent); virtual; abstract;
  59.     function GetRoot: TComponent; virtual; abstract;
  60.     procedure Revert(Instance: TPersistent; PropInfo: PPropInfo); virtual; abstract;
  61.   end;
  62.  
  63. { TPropertyEditor
  64.   Edits a property of a component, or list of components, selected into the
  65.   Object Inspector.  The property editor is created based on the type of the
  66.   property being edited as determined by the types registered by
  67.   RegisterPropertyEditor.  The Object Inspector uses the a TPropertyEditor
  68.   for all modification to a property. GetName and GetValue are called to display
  69.   the name and value of the property.  SetValue is called whenever the user
  70.   requests to change the value.  Edit is called when the user double-clicks the
  71.   property in the Object Inspector. GetValues is called when the drop-down
  72.   list of a property is displayed.  GetProperties is called when the property
  73.   is expanded to show sub-properties.  AllEqual is called to decide whether or
  74.   not to display the value of the property when more than one component is
  75.   selected.
  76.  
  77.   The following are methods that can be overriden to change the behavior of
  78.   the property editor:
  79.  
  80.     Activate
  81.       Called whenever the property becomes selected in the object inspector.
  82.       This is potientially useful to allow certian property attributes to
  83.       to only be determined whenever the property is selected in the object
  84.       inspector. Only paSubProperties and paMultiSelect, returned from
  85.       GetAttributes, need to be accurate before this method is called.
  86.     AllEqual
  87.       Called whenever there are more than one components selected.  If this
  88.       method returns true, GetValue is called, otherwise blank is displayed
  89.       in the Object Inspector.  This is called only when GetAttributes
  90.       returns paMultiSelect.
  91.     Edit
  92.       Called when the '...' button is pressed or the property is double-clicked.
  93.       This can, for example, bring up a dialog to allow the editing the
  94.       component in some more meaningful fashion than by text (e.g. the Font
  95.       property).
  96.     GetAttributes
  97.       Returns the information for use in the Object Inspector to be able to
  98.       show the approprate tools.  GetAttributes return a set of type
  99.       TPropertyAttributes:
  100.         paValueList:     The property editor can return an enumerated list of
  101.                          values for the property.  If GetValues calls Proc
  102.                          with values then this attribute should be set.  This
  103.                          will cause the drop-down button to appear to the right
  104.                          of the property in the Object Inspector.
  105.         paSortList:      Object Inspector to sort the list returned by
  106.                          GetValues.
  107.         paSubProperties: The property editor has sub-properties that will be
  108.                          displayed indented and below the current property in
  109.                          standard outline format. If GetProperties will
  110.                          generate property objects then this attribute should
  111.                          be set.
  112.         paDialog:        Indicates that the Edit method will bring up a
  113.                          dialog.  This will cause the '...' button to be
  114.                          displayed to the right of the property in the Object
  115.                          Inspector.
  116.         paMultiSelect:   Allows the property to be displayed when more than
  117.                          one component is selected.  Some properties are not
  118.                          approprate for multi-selection (e.g. the Name
  119.                          property).
  120.         paAutoUpdate:    Causes the SetValue method to be called on each
  121.                          change made to the editor instead of after the change
  122.                          has been approved (e.g. the Caption property).
  123.         paReadOnly:      Value is not allowed to change.
  124.         paRevertable:    Allows the property to be reverted to the original
  125.                          value.  Things that shouldn't be reverted are nested
  126.                          properties (e.g. Fonts) and elements of a composite
  127.                          property such as set element values.
  128.     GetComponent
  129.       Returns the Index'th component being edited by this property editor.  This
  130.       is used to retieve the components.  A property editor can only refer to
  131.       multiple components when paMultiSelect is returned from GetAttributes.
  132.     GetEditLimit
  133.       Returns the number of character the user is allowed to enter for the
  134.       value.  The inplace editor of the object inspector will be have its
  135.       text limited set to the return value.  By default this limit is 255.
  136.     GetName
  137.       Returns a the name of the property.  By default the value is retrieved
  138.       from the type information with all underbars replaced by spaces.  This
  139.       should only be overriden if the name of the property is not the name
  140.       that should appear in the Object Inspector.
  141.     GetProperties
  142.       Should be overriden to call PropertyProc for every sub-property (or nested
  143.       property) of the property begin edited and passing a new TPropertyEdtior
  144.       for each sub-property.  By default, PropertyProc is not called and no
  145.       sub-properties are assumed.  TClassProperty will pass a new property
  146.       editor for each published property in a class.  TSetProperty passes a
  147.       new editor for each element in the set.
  148.     GetPropType
  149.       Returns the type information pointer for the propertie(s) being edited.
  150.     GetValue
  151.       Returns the string value of the property. By default this returns
  152.       '(unknown)'.  This should be overriden to return the appropriate value.
  153.     GetValues
  154.       Called when paValueList is returned in GetAttributes.  Should call Proc
  155.       for every value that is acceptable for this property.  TEnumProperty
  156.       will pass every element in the enumeration.
  157.     Initialize
  158.       Called after the property editor has been created but before it is used.
  159.       Many times property editors are created and because they are not a common
  160.       property across the entire selection they are thrown away.  Initialize is
  161.       called after it is determined the property editor is going to be used by
  162.       the object inspector and not just thrown away.
  163.     SetValue(Value)
  164.       Called to set the value of the property.  The property editor should be
  165.       able to translate the string and call one of the SetXxxValue methods. If
  166.       the string is not in the correct format or not an allowed value, the
  167.       property editor should generate an exception describing the problem. Set
  168.       value can ignore all changes and allow all editing of the property be
  169.       accomplished through the Edit method (e.g. the Picture property).
  170.  
  171.   Properties and methods useful in creating a new TPropertyEditor classes:
  172.  
  173.     Name property
  174.       Returns the name of the property returned by GetName
  175.     PrivateDirectory property
  176.       It is either the .EXE or the "working directory" as specified in
  177.       DELPHI32.INI.  If the property editor needs auxilury or state files
  178.       (templates, examples, etc) they should be stored in this directory.
  179.     Properties indexed property
  180.       The TProperty objects representing all the components being edited
  181.       by the property editor.  If more than one component is selected, one
  182.       TProperty object is created for each component.  Typically, it is not
  183.       necessary to use this array since the Get/SetXxxValue methods will
  184.       propagate the values appropriatly.
  185.     Value property
  186.       The current value, as a string, of the property as returned by GetValue.
  187.     Modified
  188.       Called to indicate the value of the property has been modified.  Called
  189.       automatically by the SetXxxValue methods.  If you call a TProperty
  190.       SetXxxValue method directly, you *must* call Modified as well.
  191.     GetXxxValue
  192.       Gets the value of the first property in the Properties property.  Calls
  193.       the appropriate TProperty GetXxxValue method to retrieve the value.
  194.     SetXxxValue
  195.       Sets the value of all the properties in the Properties property.  Calls
  196.       the approprate TProperty SetXxxxValue methods to set the value. }
  197.  
  198.   TPropertyAttribute = (paValueList, paSubProperties, paDialog,
  199.     paMultiSelect, paAutoUpdate, paSortList, paReadOnly, paRevertable);
  200.   TPropertyAttributes = set of TPropertyAttribute;
  201.  
  202.   TPropertyEditor = class;
  203.  
  204.   TInstProp = record
  205.     Instance: TComponent;
  206.     PropInfo: PPropInfo;
  207.   end;
  208.  
  209.   PInstPropList = ^TInstPropList;
  210.   TInstPropList = array[0..1023] of TInstProp;
  211.  
  212.   TGetPropEditProc = procedure(Prop: TPropertyEditor) of object;
  213.  
  214.   TPropertyEditor = class
  215.   private
  216.     FDesigner: TFormDesigner;
  217.     FPropList: PInstPropList;
  218.     FPropCount: Integer;
  219.     constructor Create(ADesigner: TFormDesigner; APropCount: Integer);
  220.     function GetPrivateDirectory: string;
  221.     procedure SetPropEntry(Index: Integer; AInstance: TComponent;
  222.       APropInfo: PPropInfo);
  223.   protected
  224.     function GetPropInfo: PPropInfo;
  225.     function GetFloatValue: Extended;
  226.     function GetFloatValueAt(Index: Integer): Extended;
  227.     function GetMethodValue: TMethod;
  228.     function GetMethodValueAt(Index: Integer): TMethod;
  229.     function GetOrdValue: Longint;
  230.     function GetOrdValueAt(Index: Integer): Longint;
  231.     function GetStrValue: string;
  232.     function GetStrValueAt(Index: Integer): string;
  233.     function GetVarValue: Variant;
  234.     function GetVarValueAt(Index: Integer): Variant;
  235.     procedure Modified;
  236.     procedure SetFloatValue(Value: Extended);
  237.     procedure SetMethodValue(const Value: TMethod);
  238.     procedure SetOrdValue(Value: Longint);
  239.     procedure SetStrValue(const Value: string);
  240.     procedure SetVarValue(const Value: Variant);
  241.   public
  242.     destructor Destroy; override;
  243.     procedure Activate; virtual;
  244.     function AllEqual: Boolean; virtual;
  245.     procedure Edit; virtual;
  246.     function GetAttributes: TPropertyAttributes; virtual;
  247.     function GetComponent(Index: Integer): TComponent;
  248.     function GetEditLimit: Integer; virtual;
  249.     function GetName: string; virtual;
  250.     procedure GetProperties(Proc: TGetPropEditProc); virtual;
  251.     function GetPropType: PTypeInfo;
  252.     function GetValue: string; virtual;
  253.     procedure GetValues(Proc: TGetStrProc); virtual;
  254.     procedure Initialize; virtual;
  255.     procedure Revert;
  256.     procedure SetValue(const Value: string); virtual;
  257.     function ValueAvailable: Boolean;
  258.     property Designer: TFormDesigner read FDesigner;
  259.     property PrivateDirectory: string read GetPrivateDirectory;
  260.     property PropCount: Integer read FPropCount;
  261.     property Value: string read GetValue write SetValue;
  262.   end;
  263.  
  264.   TPropertyEditorClass = class of TPropertyEditor;
  265.  
  266. { TOrdinalProperty
  267.   The base class of all ordinal property editors.  It established that ordinal
  268.   properties are all equal if the GetOrdValue all return the same value. }
  269.  
  270.   TOrdinalProperty = class(TPropertyEditor)
  271.     function AllEqual: Boolean; override;
  272.     function GetEditLimit: Integer; override;
  273.   end;
  274.  
  275. { TIntegerProperty
  276.   Default editor for all Longint properties and all subtypes of the Longint
  277.   type (i.e. Integer, Word, 1..10, etc.).  Retricts the value entrered into
  278.   the property to the range of the sub-type. }
  279.  
  280.   TIntegerProperty = class(TOrdinalProperty)
  281.   public
  282.     function GetValue: string; override;
  283.     procedure SetValue(const Value: string); override;
  284.   end;
  285.  
  286. { TCharProperty
  287.   Default editor for all Char properties and sub-types of Char (i.e. Char,
  288.   'A'..'Z', etc.). }
  289.  
  290.   TCharProperty = class(TOrdinalProperty)
  291.   public
  292.     function GetValue: string; override;
  293.     procedure SetValue(const Value: string); override;
  294.   end;
  295.  
  296. { TEnumProperty
  297.   The default property editor for all enumerated properties (e.g. TShape =
  298.   (sCircle, sTriangle, sSquare), etc.). }
  299.  
  300.   TEnumProperty = class(TOrdinalProperty)
  301.   public
  302.     function GetAttributes: TPropertyAttributes; override;
  303.     function GetValue: string; override;
  304.     procedure GetValues(Proc: TGetStrProc); override;
  305.     procedure SetValue(const Value: string); override;
  306.   end;
  307.  
  308. { TFloatProperty
  309.   The default property editor for all floating point types (e.g. Float,
  310.   Single, Double, etc.) }
  311.  
  312.   TFloatProperty = class(TPropertyEditor)
  313.   public
  314.     function AllEqual: Boolean; override;
  315.     function GetValue: string; override;
  316.     procedure SetValue(const Value: string); override;
  317.   end;
  318.  
  319. { TStringProperty
  320.   The default property editor for all strings and sub types (e.g. string,
  321.   string[20], etc.). }
  322.  
  323.   TStringProperty = class(TPropertyEditor)
  324.   public
  325.     function AllEqual: Boolean; override;
  326.     function GetEditLimit: Integer; override;
  327.     function GetValue: string; override;
  328.     procedure SetValue(const Value: string); override;
  329.   end;
  330.  
  331. { TSetElementProperty
  332.   A property editor that edits an individual set element.  GetName is
  333.   changed to display the set element name instead of the property name and
  334.   Get/SetValue is changed to reflect the individual element state.  This
  335.   editor is created by the TSetProperty editor. }
  336.  
  337.   TSetElementProperty = class(TPropertyEditor)
  338.   private
  339.     FElement: Integer;
  340.     constructor Create(ADesigner: TFormDesigner; APropList: PInstPropList;
  341.       APropCount: Integer; AElement: Integer);
  342.   public
  343.     destructor Destroy; override;
  344.     function AllEqual: Boolean; override;
  345.     function GetAttributes: TPropertyAttributes; override;
  346.     function GetName: string; override;
  347.     function GetValue: string; override;
  348.     procedure GetValues(Proc: TGetStrProc); override;
  349.     procedure SetValue(const Value: string); override;
  350.    end;
  351.  
  352. { TSetProperty
  353.   Default property editor for all set properties. This editor does not edit
  354.   the set directly but will display sub-properties for each element of the
  355.   set. GetValue displays the value of the set in standard set syntax. }
  356.  
  357.   TSetProperty = class(TOrdinalProperty)
  358.   public
  359.     function GetAttributes: TPropertyAttributes; override;
  360.     procedure GetProperties(Proc: TGetPropEditProc); override;
  361.     function GetValue: string; override;
  362.   end;
  363.  
  364. { TClassProperty
  365.   Default proeperty editor for all objects.  Does not allow modifing the
  366.   property but does display the class name of the object and will allow the
  367.   editing of the object's properties as sub-properties of the property. }
  368.  
  369.   TClassProperty = class(TPropertyEditor)
  370.   public
  371.     function GetAttributes: TPropertyAttributes; override;
  372.     procedure GetProperties(Proc: TGetPropEditProc); override;
  373.     function GetValue: string; override;
  374.   end;
  375.  
  376. { TMethodProperty
  377.   Property editor for all method properties. }
  378.  
  379.   TMethodProperty = class(TPropertyEditor)
  380.   public
  381.     function AllEqual: Boolean; override;
  382.     procedure Edit; override;
  383.     function GetAttributes: TPropertyAttributes; override;
  384.     function GetEditLimit: Integer; override;
  385.     function GetValue: string; override;
  386.     procedure GetValues(Proc: TGetStrProc); override;
  387.     procedure SetValue(const AValue: string); override;
  388.   end;
  389.  
  390. { TComponentProperty
  391.   The default editor for TComponents.  It does not allow editing of the
  392.   properties of the component.  It allow the user to set the value of this
  393.   property to point to a component in the same form that is type compatible
  394.   with the property being edited (e.g. the ActiveControl property). }
  395.  
  396.   TComponentProperty = class(TPropertyEditor)
  397.   public
  398.     function GetAttributes: TPropertyAttributes; override;
  399.     function GetEditLimit: Integer; override;
  400.     function GetValue: string; override;
  401.     procedure GetValues(Proc: TGetStrProc); override;
  402.     procedure SetValue(const Value: string); override;
  403.   end;
  404.  
  405. { TComponentNameProperty
  406.   Property editor for the Name property.  It restricts the name property
  407.   from being displayed when more than one component is selected. }
  408.  
  409.   TComponentNameProperty = class(TStringProperty)
  410.   public
  411.     function GetAttributes: TPropertyAttributes; override;
  412.     function GetEditLimit: Integer; override;
  413.   end;
  414.  
  415. { TFontNameProperty
  416.   Editor for the TFont.FontName property.  Displays a drop-down list of all
  417.   the fonts known by Windows.}
  418.  
  419.   TFontNameProperty = class(TStringProperty)
  420.   public
  421.     function GetAttributes: TPropertyAttributes; override;
  422.     procedure GetValues(Proc: TGetStrProc); override;
  423.   end;
  424.  
  425.  
  426. { TColorProperty
  427.   Property editor for the TColor type.  Displays the color as a clXXX value
  428.   if one exists, otherwise displays the value as hex.  Also allows the
  429.   clXXX value to be picked from a list. }
  430.  
  431.   TColorProperty = class(TIntegerProperty)
  432.   public
  433.     procedure Edit; override;
  434.     function GetAttributes: TPropertyAttributes; override;
  435.     function GetValue: string; override;
  436.     procedure GetValues(Proc: TGetStrProc); override;
  437.     procedure SetValue(const Value: string); override;
  438.   end;
  439.  
  440. { TCursorProperty
  441.   Property editor for the TCursor type.  Displays the color as a crXXX value
  442.   if one exists, otherwise displays the value as hex.  Also allows the
  443.   clXXX value to be picked from a list. }
  444.  
  445.   TCursorProperty = class(TIntegerProperty)
  446.   public
  447.     function GetAttributes: TPropertyAttributes; override;
  448.     function GetValue: string; override;
  449.     procedure GetValues(Proc: TGetStrProc); override;
  450.     procedure SetValue(const Value: string); override;
  451.   end;
  452.  
  453. { TFontProperty
  454.   Property editor the Font property.  Brings up the font dialog as well as
  455.   allowing the properties of the object to be edited. }
  456.  
  457.   TFontProperty = class(TClassProperty)
  458.   public
  459.     procedure Edit; override;
  460.     function GetAttributes: TPropertyAttributes; override;
  461.   end;
  462.  
  463. { TModalResultProperty }
  464.  
  465.   TModalResultProperty = class(TIntegerProperty)
  466.   public
  467.     function GetAttributes: TPropertyAttributes; override;
  468.     function GetValue: string; override;
  469.     procedure GetValues(Proc: TGetStrProc); override;
  470.     procedure SetValue(const Value: string); override;
  471.   end;
  472.  
  473. { TShortCutProperty
  474.   Property editor the the ShortCut property.  Allows both typing in a short
  475.   cut value or picking a short-cut value from a list. }
  476.  
  477.   TShortCutProperty = class(TOrdinalProperty)
  478.   public
  479.     function GetAttributes: TPropertyAttributes; override;
  480.     function GetValue: string; override;
  481.     procedure GetValues(Proc: TGetStrProc); override;
  482.     procedure SetValue(const Value: string); override;
  483.   end;
  484.  
  485. { TMPFilenameProperty
  486.   Property editor for the TMediaPlayer.  Displays an File Open Dialog
  487.   for the name of the media file.}
  488.  
  489.   TMPFilenameProperty = class(TStringProperty)
  490.   public
  491.     procedure Edit; override;
  492.     function GetAttributes: TPropertyAttributes; override;
  493.   end;
  494.  
  495. { TTabOrderProperty
  496.   Property editor for the TabOrder property.  Prevents the property from being
  497.   displayed when more than one component is selected. }
  498.  
  499.   TTabOrderProperty = class(TIntegerProperty)
  500.   public
  501.     function GetAttributes: TPropertyAttributes; override;
  502.   end;
  503.  
  504. { TCaptionProperty
  505.   Property editor for the Caption and Text properties.  Updates the value of
  506.   the property for each change instead on when the property is approved. }
  507.  
  508.   TCaptionProperty = class(TStringProperty)
  509.   public
  510.     function GetAttributes: TPropertyAttributes; override;
  511.   end;
  512.  
  513.   EPropertyError = class(Exception);
  514.  
  515. { TComponentEditor
  516.   A component editor is created for each component that is selected in the
  517.   form designer based on the component's type (see GetComponentEditor and
  518.   RegisterComponentEditor).  When the component is double-clicked the Edit
  519.   method is called.  When the context menu for the component is invoked the
  520.   GetVerbCount and GetVerb methods are called to build the menu.  If one
  521.   of the verbs are selected ExecuteVerb is called.  Paste is called whenever
  522.   the component is pasted to the clipboard.  You only need to create a
  523.   component editor if you wish to add verbs to the context menu, change
  524.   the default double-click behavior, or paste an additional clipboard format.
  525.   The default component editor (TDefaultEditor) implements Edit to searchs the
  526.   properties of the component and generates (or navigates to) the OnCreate,
  527.   OnChanged, or OnClick event (whichever it finds first).  Whenever the
  528.   component modifies the component is *must* call Designer.Modified to inform
  529.   the designer that the form has been modified.
  530.  
  531.     Create(AComponent, ADesigner)
  532.       Called to create the component editor.  AComponent is the component to
  533.       be edited by the editor.  ADesigner is an interface to the designer to
  534.       find controls and create methods (this is not use often).
  535.     Edit
  536.       Called when the user double-clicks the component. The component editor can
  537.       bring up a dialog in responce to this method, for example, or some kind
  538.       of design expert.  If GetVerbCount is greater than zero, edit will execute
  539.       the first verb in the list (ExecuteVerb(0)).
  540.     ExecuteVerb(Index)
  541.       The Index'ed verb was selected by the use off the context menu.  The
  542.       meaning of this is determined by component editor.
  543.     GetVerb
  544.       The component editor should return a string that will be displayed in the
  545.       context menu.  It is the responsibility of the component editor to place
  546.       the & character and the '...' characters as appropriate.
  547.     GetVerbCount
  548.       The number of valid indexs to GetVerb and Execute verb.  The index assumed
  549.       to be zero based (i.e. 0..GetVerbCount - 1).
  550.     Copy
  551.       Called when the component is being copyied to the clipboard.  The
  552.       component's filed image is already on the clipboard.  This gives the
  553.       component editor a chance to paste a different type of format which is
  554.       ignored by the designer but might be recoginized by another application. }
  555.  
  556.   TComponentEditor = class
  557.   private
  558.     FComponent: TComponent;
  559.     FDesigner: TFormDesigner;
  560.   public
  561.     constructor Create(AComponent: TComponent; ADesigner: TFormDesigner); virtual;
  562.     procedure Edit; virtual;
  563.     procedure ExecuteVerb(Index: Integer); virtual;
  564.     function GetVerb(Index: Integer): string; virtual;
  565.     function GetVerbCount: Integer; virtual;
  566.     procedure Copy; virtual;
  567.     property Component: TComponent read FComponent;
  568.     property Designer: TFormDesigner read FDesigner;
  569.   end;
  570.  
  571.   TComponentEditorClass = class of TComponentEditor;
  572.  
  573.   TDefaultEditor = class(TComponentEditor)
  574.   private
  575.     FFirst: TPropertyEditor;
  576.     FBest: TPropertyEditor;
  577.     FContinue: Boolean;
  578.     procedure CheckEdit(PropertyEditor: TPropertyEditor);
  579.   protected
  580.     procedure EditProperty(PropertyEditor: TPropertyEditor;
  581.       var Continue, FreeEditor: Boolean); virtual;
  582.   public
  583.     procedure Edit; override;
  584.   end;
  585.  
  586.   TPropertyMapperFunc = function(Component: TComponent;
  587.     PropInfo: PPropInfo): TPropertyEditorClass;
  588.  
  589. { RegisterPropertyEditor
  590.   Registers a new property editor for the given type.  When a component is
  591.   selected the Object Inspector will create a property editor for each
  592.   of the component's properties.  The property editor is created based on
  593.   the type of the property.  If, for example, the property type is an
  594.   Integer, the property editor for Integer will be created (by default
  595.   that would be TIntegerProperty). Most properties do not need specialized
  596.   property editors.  For example, if the property is an ordinal type the
  597.   default property editor will restrict the range to the ordinal subtype
  598.   range (e.g. a property of type TMyRange = 1..10 will only allow values
  599.   between 1 and 10 to be entered into the property).  Enumerated types will
  600.   display a drop-down list of all the enumerated values (e.g. TShapes =
  601.   (sCircle, sSquare, sTriangle) will be edited by a drop-down list containing
  602.   only sCircle, sSquare and sTriangle).  A property editor need only be
  603.   created if default property editor or none of the existing property editors
  604.   are sufficient to edit the property.  This is typically because the
  605.   property is an object.  The properties are looked up newest to oldest.
  606.   This allows and existing property editor replaced by a custom property
  607.   editor.
  608.  
  609.     PropertyType
  610.       The type information pointer returned by the TypeInfo built-in function
  611.       (e.g. TypeInfo(TMyRange) or TypeInfo(TShapes)).
  612.  
  613.     ComponentClass
  614.       Type type of the component to which to restrict this type editor.  This
  615.       parameter can be left nil which will mean this type editor applies to all
  616.       properties of PropertyType.
  617.  
  618.     PropertyName
  619.       The name of the property to which to restrict this type editor.  This
  620.       parameter is ignored if ComponentClass is nil.  This paramter can be
  621.       an empty string ('') which will mean that this editor applies to all
  622.       properties of PropertyType in ComponentClass.
  623.  
  624.     EditorClass
  625.       The class of the editor to be created whenever a property of the type
  626.       passed in PropertyTypeInfo is displayed in the Object Inspector.  The
  627.       class will be created by calling EditorClass.Create. }
  628.  
  629. procedure RegisterPropertyEditor(PropertyType: PTypeInfo; ComponentClass: TClass;
  630.   const PropertyName: string; EditorClass: TPropertyEditorClass);
  631.  
  632. procedure RegisterPropertyMapper(Mapper: TPropertyMapperFunc);
  633.  
  634. procedure GetComponentProperties(Components: TComponentList;
  635.   Filter: TTypeKinds; Designer: TFormDesigner; Proc: TGetPropEditProc);
  636.  
  637. procedure RegisterComponentEditor(ComponentClass: TComponentClass;
  638.   ComponentEditor: TComponentEditorClass);
  639.  
  640. function GetComponentEditor(Component: TComponent;
  641.   Designer: TFormDesigner): TComponentEditor;
  642.  
  643. implementation
  644.  
  645. uses Windows, Menus, Dialogs, Consts, IniFiles;
  646.  
  647. type
  648.   TIntegerSet = set of 0..SizeOf(Integer) * 8 - 1;
  649.  
  650. type
  651.   PPropertyClassRec = ^TPropertyClassRec;
  652.   TPropertyClassRec = record
  653.     Next: PPropertyClassRec;
  654.     PropertyType: PTypeInfo;
  655.     PropertyName: string;
  656.     ComponentClass: TClass;
  657.     EditorClass: TPropertyEditorClass;
  658.   end;
  659.  
  660. type
  661.   PPropertyMapperRec = ^TPropertyMapperRec;
  662.   TPropertyMapperRec = record
  663.     Next: PPropertyMapperRec;
  664.     Mapper: TPropertyMapperFunc;
  665.   end;
  666.  
  667. const
  668.   PropClassMap: array[TTypeKind] of TPropertyEditorClass = (
  669.     TPropertyEditor, TIntegerProperty, TCharProperty, TEnumProperty,
  670.     TFloatProperty, TStringProperty, TSetProperty, TClassProperty,
  671.     TMethodProperty, TPropertyEditor, TStringProperty, TPropertyEditor,
  672.     TPropertyEditor);
  673.  
  674. var
  675.   PropertyClassList: PPropertyClassRec = nil;
  676.   PropertyMapperList: PPropertyMapperRec = nil;
  677.  
  678. const
  679.  
  680.   { context ids for the Font editor and the Color Editor, etc. }
  681.   hcDFontEditor       = 25000;
  682.   hcDColorEditor      = 25010;
  683.   hcDMediaPlayerOpen  = 25020;
  684.  
  685. { TComponentList }
  686.  
  687. constructor TComponentList.Create;
  688. begin
  689.   inherited Create;
  690.   FList := TList.Create;
  691. end;
  692.  
  693. destructor TComponentList.Destroy;
  694. begin
  695.   FList.Free;
  696.   inherited Destroy;
  697. end;
  698.  
  699. function TComponentList.Get(Index: Integer): TComponent;
  700. begin
  701.   Result := FList[Index];
  702. end;
  703.  
  704. function TComponentList.GetCount: Integer;
  705. begin
  706.   Result := FList.Count;
  707. end;
  708.  
  709. function TComponentList.Add(Item: TComponent): Integer;
  710. begin
  711.   Result := FList.Add(Item);
  712. end;
  713.  
  714. function TComponentList.Equals(List: TComponentList): Boolean;
  715. var
  716.   I: Integer;
  717. begin
  718.   Result := False;
  719.   if List.Count <> FList.Count then Exit;
  720.   for I := 0 to List.Count - 1 do if List[I] <> FList[I] then Exit;
  721.   Result := True;
  722. end;
  723.  
  724. { TPropertyEditor }
  725.  
  726. constructor TPropertyEditor.Create(ADesigner: TFormDesigner;
  727.   APropCount: Integer);
  728. begin
  729.   FDesigner := ADesigner;
  730.   GetMem(FPropList, APropCount * SizeOf(TInstProp));
  731.   FPropCount := APropCount;
  732. end;
  733.  
  734. destructor TPropertyEditor.Destroy;
  735. begin
  736.   if FPropList <> nil then
  737.     FreeMem(FPropList, FPropCount * SizeOf(TInstProp));
  738. end;
  739.  
  740. procedure TPropertyEditor.Activate;
  741. begin
  742. end;
  743.  
  744. function TPropertyEditor.AllEqual: Boolean;
  745. begin
  746.   Result := FPropCount = 1;
  747. end;
  748.  
  749. procedure TPropertyEditor.Edit;
  750. type
  751.   TGetStrFunc = function(const Value: string): Integer of object;
  752. var
  753.   I: Integer;
  754.   Values: TStringList;
  755.   AddValue: TGetStrFunc;
  756. begin
  757.   Values := TStringList.Create;
  758.   Values.Sorted := paSortList in GetAttributes;
  759.   try
  760.     AddValue := Values.Add;
  761.     GetValues(TGetStrProc(AddValue));
  762.     if Values.Count > 0 then
  763.     begin
  764.       I := Values.IndexOf(Value) + 1;
  765.       if I = Values.Count then I := 0;
  766.       Value := Values[I];
  767.     end;
  768.   finally
  769.     Values.Free;
  770.   end;
  771. end;
  772.  
  773. function TPropertyEditor.GetAttributes: TPropertyAttributes;
  774. begin
  775.   Result := [paMultiSelect, paRevertable];
  776. end;
  777.  
  778. function TPropertyEditor.GetComponent(Index: Integer): TComponent;
  779. begin
  780.   Result := FPropList^[Index].Instance;
  781. end;
  782.  
  783. function TPropertyEditor.GetFloatValue: Extended;
  784. begin
  785.   Result := GetFloatValueAt(0);
  786. end;
  787.  
  788. function TPropertyEditor.GetFloatValueAt(Index: Integer): Extended;
  789. begin
  790.   with FPropList^[Index] do Result := GetFloatProp(Instance, PropInfo);
  791. end;
  792.  
  793. function TPropertyEditor.GetMethodValue: TMethod;
  794. begin
  795.   Result := GetMethodValueAt(0);
  796. end;
  797.  
  798. function TPropertyEditor.GetMethodValueAt(Index: Integer): TMethod;
  799. begin
  800.   with FPropList^[Index] do Result := GetMethodProp(Instance, PropInfo);
  801. end;
  802.  
  803. function TPropertyEditor.GetEditLimit: Integer;
  804. begin
  805.   Result := 255;
  806. end;
  807.  
  808. function TPropertyEditor.GetName: string;
  809. begin
  810.   Result := FPropList^[0].PropInfo^.Name;
  811. end;
  812.  
  813. function TPropertyEditor.GetOrdValue: Longint;
  814. begin
  815.   Result := GetOrdValueAt(0);
  816. end;
  817.  
  818. function TPropertyEditor.GetOrdValueAt(Index: Integer): Longint;
  819. begin
  820.   with FPropList^[Index] do Result := GetOrdProp(Instance, PropInfo);
  821. end;
  822.  
  823. function TPropertyEditor.GetPrivateDirectory: string;
  824. begin
  825.   Result := Designer.GetPrivateDirectory;
  826. end;
  827.  
  828. procedure TPropertyEditor.GetProperties(Proc: TGetPropEditProc);
  829. begin
  830. end;
  831.  
  832. function TPropertyEditor.GetPropInfo: PPropInfo;
  833. begin
  834.   Result := FPropList^[0].PropInfo;
  835. end;
  836.  
  837. function TPropertyEditor.GetPropType: PTypeInfo;
  838. begin
  839.   Result := FPropList^[0].PropInfo^.PropType;
  840. end;
  841.  
  842. function TPropertyEditor.GetStrValue: string;
  843. begin
  844.   Result := GetStrValueAt(0);
  845. end;
  846.  
  847. function TPropertyEditor.GetStrValueAt(Index: Integer): string;
  848. begin
  849.   with FPropList^[Index] do Result := GetStrProp(Instance, PropInfo);
  850. end;
  851.  
  852. function TPropertyEditor.GetVarValue: Variant;
  853. begin
  854.   Result := GetVarValueAt(0);
  855. end;
  856.  
  857. function TPropertyEditor.GetVarValueAt(Index: Integer): Variant;
  858. begin
  859.   VarClear(Result);
  860.   with FPropList^[Index] do Result := GetVariantProp(Instance, PropInfo);
  861. end;
  862.  
  863. function TPropertyEditor.GetValue: string;
  864. begin
  865.   Result := LoadStr(srUnknown);
  866. end;
  867.  
  868. procedure TPropertyEditor.GetValues(Proc: TGetStrProc);
  869. begin
  870. end;
  871.  
  872. procedure TPropertyEditor.Initialize;
  873. begin
  874. end;
  875.  
  876. procedure TPropertyEditor.Modified;
  877. begin
  878.   Designer.Modified;
  879. end;
  880.  
  881. procedure TPropertyEditor.SetFloatValue(Value: Extended);
  882. var
  883.   I: Integer;
  884. begin
  885.   for I := 0 to FPropCount - 1 do
  886.     with FPropList^[I] do SetFloatProp(Instance, PropInfo, Value);
  887.   Modified;
  888. end;
  889.  
  890. procedure TPropertyEditor.SetMethodValue(const Value: TMethod);
  891. var
  892.   I: Integer;
  893. begin
  894.   for I := 0 to FPropCount - 1 do
  895.     with FPropList^[I] do SetMethodProp(Instance, PropInfo, Value);
  896.   Modified;
  897. end;
  898.  
  899. procedure TPropertyEditor.SetOrdValue(Value: Longint);
  900. var
  901.   I: Integer;
  902. begin
  903.   for I := 0 to FPropCount - 1 do
  904.     with FPropList^[I] do SetOrdProp(Instance, PropInfo, Value);
  905.   Modified;
  906. end;
  907.  
  908. procedure TPropertyEditor.SetPropEntry(Index: Integer;
  909.   AInstance: TComponent; APropInfo: PPropInfo);
  910. begin
  911.   with FPropList^[Index] do
  912.   begin
  913.     Instance := AInstance;
  914.     PropInfo := APropInfo;
  915.   end;
  916. end;
  917.  
  918. procedure TPropertyEditor.SetStrValue(const Value: string);
  919. var
  920.   I: Integer;
  921. begin
  922.   for I := 0 to FPropCount - 1 do
  923.     with FPropList^[I] do SetStrProp(Instance, PropInfo, Value);
  924.   Modified;
  925. end;
  926.  
  927. procedure TPropertyEditor.SetVarValue(const Value: Variant);
  928. var
  929.   I: Integer;
  930. begin
  931.   for I := 0 to FPropCount - 1 do
  932.     with FPropList^[I] do SetVariantProp(Instance, PropInfo, Value);
  933.   Modified;
  934. end;
  935.  
  936. procedure TPropertyEditor.Revert;
  937. var
  938.   I: Integer;
  939. begin
  940.   for I := 0 to FPropCount - 1 do
  941.     with FPropList^[I] do Designer.Revert(Instance, PropInfo);
  942. end;
  943.  
  944. procedure TPropertyEditor.SetValue(const Value: string);
  945. begin
  946. end;
  947.  
  948. function TPropertyEditor.ValueAvailable: Boolean;
  949. var
  950.   I: Integer;
  951.   S: string;
  952. begin
  953.   Result := True;
  954.   for I := 0 to FPropCount - 1 do
  955.   begin
  956.     if csCheckPropAvail in FPropList^[I].Instance.ComponentStyle then
  957.     begin
  958.       try
  959.         S := GetValue;
  960.         AllEqual;
  961.       except
  962.         Result := False;
  963.       end;
  964.       Exit;
  965.     end;
  966.   end;
  967. end;
  968.  
  969. { TOrdinalProperty }
  970.  
  971. function TOrdinalProperty.AllEqual: Boolean;
  972. var
  973.   I: Integer;
  974.   V: Longint;
  975. begin
  976.   Result := False;
  977.   if PropCount > 1 then
  978.   begin
  979.     V := GetOrdValue;
  980.     for I := 1 to PropCount - 1 do
  981.       if GetOrdValueAt(I) <> V then Exit;
  982.   end;
  983.   Result := True;
  984. end;
  985.  
  986. function TOrdinalProperty.GetEditLimit: Integer;
  987. begin
  988.   Result := 63;
  989. end;
  990.  
  991. { TIntegerProperty }
  992.  
  993. function TIntegerProperty.GetValue: string;
  994. begin
  995.   Result := IntToStr(GetOrdValue);
  996. end;
  997.  
  998. procedure TIntegerProperty.SetValue(const Value: String);
  999. var
  1000.   L: Longint;
  1001. begin
  1002.   L := StrToInt(Value);
  1003.   with GetTypeData(GetPropType)^ do
  1004.     if (L < MinValue) or (L > MaxValue) then
  1005.       raise EPropertyError.CreateResFmt(SOutOfRange, [MinValue, MaxValue]);
  1006.   SetOrdValue(L);
  1007. end;
  1008.  
  1009. { TCharProperty }
  1010.  
  1011. function TCharProperty.GetValue: string;
  1012. var
  1013.   Ch: Char;
  1014. begin
  1015.   Ch := Chr(GetOrdValue);
  1016.   if Ch in [#33..#127] then
  1017.     Result := Ch else
  1018.     FmtStr(Result, '#%d', [Ord(Ch)]);
  1019. end;
  1020.  
  1021. procedure TCharProperty.SetValue(const Value: string);
  1022. var
  1023.   L: Longint;
  1024. begin
  1025.   if Length(Value) = 0 then L := 0 else
  1026.     if Length(Value) = 1 then L := Ord(Value[1]) else
  1027.       if Value[1] = '#' then L := StrToInt(Copy(Value, 2, Maxint)) else
  1028.         raise EPropertyError.CreateRes(SInvalidPropertyValue);
  1029.   with GetTypeData(GetPropType)^ do
  1030.     if (L < MinValue) or (L > MaxValue) then
  1031.       raise EPropertyError.CreateResFmt(SOutOfRange, [MinValue, MaxValue]);
  1032.   SetOrdValue(L);
  1033. end;
  1034.  
  1035. { TEnumProperty }
  1036.  
  1037. function TEnumProperty.GetAttributes: TPropertyAttributes;
  1038. begin
  1039.   Result := [paMultiSelect, paValueList, paSortList, paRevertable];
  1040. end;
  1041.  
  1042. function TEnumProperty.GetValue: string;
  1043. var
  1044.   L: Longint;
  1045. begin
  1046.   L := GetOrdValue;
  1047.   with GetTypeData(GetPropType)^ do
  1048.     if (L < MinValue) or (L > MaxValue) then L := MaxValue;
  1049.   Result := GetEnumName(GetPropType, L);
  1050. end;
  1051.  
  1052. procedure TEnumProperty.GetValues(Proc: TGetStrProc);
  1053. var
  1054.   I: Integer;
  1055.   EnumType: PTypeInfo;
  1056. begin
  1057.   EnumType := GetPropType;
  1058.   with GetTypeData(EnumType)^ do
  1059.     for I := MinValue to MaxValue do Proc(GetEnumName(EnumType, I));
  1060. end;
  1061.  
  1062. procedure TEnumProperty.SetValue(const Value: string);
  1063. var
  1064.   I: Integer;
  1065. begin
  1066.   I := GetEnumValue(GetPropType, Value);
  1067.   if I < 0 then raise EPropertyError.CreateRes(SInvalidPropertyValue);
  1068.   SetOrdValue(I);
  1069. end;
  1070.  
  1071. { TFloatProperty }
  1072.  
  1073. function TFloatProperty.AllEqual: Boolean;
  1074. var
  1075.   I: Integer;
  1076.   V: Extended;
  1077. begin
  1078.   Result := False;
  1079.   if PropCount > 1 then
  1080.   begin
  1081.     V := GetFloatValue;
  1082.     for I := 1 to PropCount - 1 do
  1083.       if GetFloatValueAt(I) <> V then Exit;
  1084.   end;
  1085.   Result := True;
  1086. end;
  1087.  
  1088. function TFloatProperty.GetValue: string;
  1089. const
  1090.   Precisions: array[TFloatType] of Integer = (7, 15, 18, 18, 18);
  1091. begin
  1092.   Result := FloatToStrF(GetFloatValue, ffGeneral,
  1093.     Precisions[GetTypeData(GetPropType)^.FloatType], 0);
  1094. end;
  1095.  
  1096. procedure TFloatProperty.SetValue(const Value: string);
  1097. begin
  1098.   SetFloatValue(StrToFloat(Value));
  1099. end;
  1100.  
  1101. { TStringProperty }
  1102.  
  1103. function TStringProperty.AllEqual: Boolean;
  1104. var
  1105.   I: Integer;
  1106.   V: string;
  1107. begin
  1108.   Result := False;
  1109.   if PropCount > 1 then
  1110.   begin
  1111.     V := GetStrValue;
  1112.     for I := 1 to PropCount - 1 do
  1113.       if GetStrValueAt(I) <> V then Exit;
  1114.   end;
  1115.   Result := True;
  1116. end;
  1117.  
  1118. function TStringProperty.GetEditLimit: Integer;
  1119. begin
  1120.   if GetPropType^.Kind = tkString then
  1121.     Result := GetTypeData(GetPropType)^.MaxLength else
  1122.     Result := 255;
  1123. end;
  1124.  
  1125. function TStringProperty.GetValue: string;
  1126. begin
  1127.   Result := GetStrValue;
  1128. end;
  1129.  
  1130. procedure TStringProperty.SetValue(const Value: string);
  1131. begin
  1132.   SetStrValue(Value);
  1133. end;
  1134.  
  1135. { TComponentNameProperty }
  1136.  
  1137. function TComponentNameProperty.GetAttributes: TPropertyAttributes;
  1138. begin
  1139.   Result := [];
  1140. end;
  1141.  
  1142. function TComponentNameProperty.GetEditLimit: Integer;
  1143. begin
  1144.   Result := 63;
  1145. end;
  1146.  
  1147. { TSetElementProperty }
  1148.  
  1149. constructor TSetElementProperty.Create(ADesigner: TFormDesigner;
  1150.   APropList: PInstPropList; APropCount: Integer; AElement: Integer);
  1151. begin
  1152.   FDesigner := ADesigner;
  1153.   FPropList := APropList;
  1154.   FPropCount := APropCount;
  1155.   FElement := AElement;
  1156. end;
  1157.  
  1158. destructor TSetElementProperty.Destroy;
  1159. begin
  1160. end;
  1161.  
  1162. function TSetElementProperty.AllEqual: Boolean;
  1163. var
  1164.   I: Integer;
  1165.   S: TIntegerSet;
  1166.   V: Boolean;
  1167. begin
  1168.   Result := False;
  1169.   if PropCount > 1 then
  1170.   begin
  1171.     Integer(S) := GetOrdValue;
  1172.     V := FElement in S;
  1173.     for I := 1 to PropCount - 1 do
  1174.     begin
  1175.       Integer(S) := GetOrdValueAt(I);
  1176.       if (FElement in S) <> V then Exit;
  1177.     end;
  1178.   end;
  1179.   Result := True;
  1180. end;
  1181.  
  1182. function TSetElementProperty.GetAttributes: TPropertyAttributes;
  1183. begin
  1184.   Result := [paMultiSelect, paValueList, paSortList];
  1185. end;
  1186.  
  1187. function TSetElementProperty.GetName: string;
  1188. begin
  1189.   Result := GetEnumName(GetTypeData(GetPropType)^.CompType, FElement);
  1190. end;
  1191.  
  1192. function TSetElementProperty.GetValue: string;
  1193. var
  1194.   S: TIntegerSet;
  1195. begin
  1196.   Integer(S) := GetOrdValue;
  1197.   if FElement in S then Result := 'True' else Result := 'False';
  1198. end;
  1199.  
  1200. procedure TSetElementProperty.GetValues(Proc: TGetStrProc);
  1201. begin
  1202.   Proc('False');
  1203.   Proc('True');
  1204. end;
  1205.  
  1206. procedure TSetElementProperty.SetValue(const Value: string);
  1207. var
  1208.   S: TIntegerSet;
  1209. begin
  1210.   Integer(S) := GetOrdValue;
  1211.   if CompareText(Value, 'True') = 0 then
  1212.     Include(S, FElement) else
  1213.     Exclude(S, FElement);
  1214.   SetOrdValue(Integer(S));
  1215. end;
  1216.  
  1217. { TSetProperty }
  1218.  
  1219. function TSetProperty.GetAttributes: TPropertyAttributes;
  1220. begin
  1221.   Result := [paMultiSelect, paSubProperties, paReadOnly, paRevertable];
  1222. end;
  1223.  
  1224. procedure TSetProperty.GetProperties(Proc: TGetPropEditProc);
  1225. var
  1226.   I: Integer;
  1227. begin
  1228.   with GetTypeData(GetTypeData(GetPropType)^.CompType)^ do
  1229.     for I := MinValue to MaxValue do
  1230.       Proc(TSetElementProperty.Create(FDesigner, FPropList, FPropCount, I));
  1231. end;
  1232.  
  1233. function TSetProperty.GetValue: string;
  1234. var
  1235.   S: TIntegerSet;
  1236.   TypeInfo: PTypeInfo;
  1237.   I: Integer;
  1238. begin
  1239.   Integer(S) := GetOrdValue;
  1240.   TypeInfo := GetTypeData(GetPropType)^.CompType;
  1241.   Result := '[';
  1242.   for I := 0 to SizeOf(Integer) * 8 - 1 do
  1243.     if I in S then
  1244.     begin
  1245.       if Length(Result) <> 1 then Result := Result + ',';
  1246.       Result := Result + GetEnumName(TypeInfo, I);
  1247.     end;
  1248.   Result := Result + ']';
  1249. end;
  1250.  
  1251. { TClassProperty }
  1252.  
  1253. function TClassProperty.GetAttributes: TPropertyAttributes;
  1254. begin
  1255.   Result := [paMultiSelect, paSubProperties, paReadOnly];
  1256. end;
  1257.  
  1258. procedure TClassProperty.GetProperties(Proc: TGetPropEditProc);
  1259. var
  1260.   I: Integer;
  1261.   Components: TComponentList;
  1262. begin
  1263.   Components := TComponentList.Create;
  1264.   try
  1265.     for I := 0 to PropCount - 1 do
  1266.       Components.Add(TComponent(GetOrdValueAt(I)));
  1267.     GetComponentProperties(Components, tkProperties, Designer, Proc);
  1268.   finally
  1269.     Components.Free;
  1270.   end;
  1271. end;
  1272.  
  1273. function TClassProperty.GetValue: string;
  1274. begin
  1275.   FmtStr(Result, '(%s)', [GetPropType^.Name]);
  1276. end;
  1277.  
  1278. { TComponentProperty }
  1279.  
  1280. function TComponentProperty.GetAttributes: TPropertyAttributes;
  1281. begin
  1282.   Result := [paMultiSelect, paValueList, paSortList, paRevertable];
  1283. end;
  1284.  
  1285. function TComponentProperty.GetEditLimit: Integer;
  1286. begin
  1287.   Result := 127;
  1288. end;
  1289.  
  1290. function TComponentProperty.GetValue: string;
  1291. begin
  1292.   Result := Designer.GetComponentName(TComponent(GetOrdValue));
  1293. end;
  1294.  
  1295. procedure TComponentProperty.GetValues(Proc: TGetStrProc);
  1296. begin
  1297.   Designer.GetComponentNames(GetTypeData(GetPropType), Proc);
  1298. end;
  1299.  
  1300. procedure TComponentProperty.SetValue(const Value: string);
  1301. var
  1302.   Component: TComponent;
  1303. begin
  1304.   if Value = '' then Component := nil else
  1305.   begin
  1306.     Component := Designer.GetComponent(Value);
  1307.     if not (Component is GetTypeData(GetPropType)^.ClassType) then
  1308.       raise EPropertyError.CreateRes(SInvalidPropertyValue);
  1309.   end;
  1310.   SetOrdValue(Longint(Component));
  1311. end;
  1312.  
  1313. { TMethodProperty }
  1314.  
  1315. function TMethodProperty.AllEqual: Boolean;
  1316. var
  1317.   I: Integer;
  1318.   V, T: TMethod;
  1319. begin
  1320.   Result := False;
  1321.   if PropCount > 1 then
  1322.   begin
  1323.     V := GetMethodValue;
  1324.     for I := 1 to PropCount - 1 do
  1325.     begin
  1326.       T := GetMethodValueAt(I);
  1327.       if (T.Code <> V.Code) or (T.Data <> V.Data) then Exit;
  1328.     end;
  1329.   end;
  1330.   Result := True;
  1331. end;
  1332.  
  1333. procedure TMethodProperty.Edit;
  1334. var
  1335.   FormMethodName, EventName: string;
  1336. begin
  1337.   FormMethodName := GetValue;
  1338.   if (FormMethodName = '') or
  1339.     Designer.MethodFromAncestor(GetMethodValue) then
  1340.   begin
  1341.     if FormMethodName = '' then
  1342.     begin
  1343.       if GetComponent(0) = Designer.Form then
  1344.         FormMethodName := 'Form' else
  1345.         FormMethodName := GetComponent(0).Name;
  1346.       if FormMethodName = '' then
  1347.         raise EPropertyError.CreateRes(SCannotCreateName);
  1348.       EventName := GetName;
  1349.       if CompareText(Copy(EventName, 1, 2), 'ON') = 0 then
  1350.         EventName := Copy(EventName, 3, Maxint);
  1351.       FormMethodName := FormMethodName + EventName;
  1352.     end;
  1353.     SetMethodValue(Designer.CreateMethod(FormMethodName,
  1354.       GetTypeData(GetPropType)));
  1355.   end;
  1356.   Designer.ShowMethod(FormMethodName);
  1357. end;
  1358.  
  1359. function TMethodProperty.GetAttributes: TPropertyAttributes;
  1360. begin
  1361.   Result := [paMultiSelect, paValueList, paSortList, paRevertable];
  1362. end;
  1363.  
  1364. function TMethodProperty.GetEditLimit: Integer;
  1365. begin
  1366.   Result := 63;
  1367. end;
  1368.  
  1369. function TMethodProperty.GetValue: string;
  1370. begin
  1371.   Result := Designer.GetMethodName(GetMethodValue);
  1372. end;
  1373.  
  1374. procedure TMethodProperty.GetValues(Proc: TGetStrProc);
  1375. begin
  1376.   Designer.GetMethods(GetTypeData(GetPropType), Proc);
  1377. end;
  1378.  
  1379. procedure TMethodProperty.SetValue(const AValue: string);
  1380. var
  1381.   NewMethod: Boolean;
  1382.   CurValue: string;
  1383. begin
  1384.   CurValue:= GetValue;
  1385.   if (CurValue <> '') and (AValue <> '') and
  1386.     ((CompareText(CurValue, AValue) = 0) or
  1387.     not Designer.MethodExists(AValue)) then
  1388.     Designer.RenameMethod(CurValue, AValue)
  1389.   else
  1390.   begin
  1391.     NewMethod := (AValue <> '') and not Designer.MethodExists(AValue);
  1392.     SetMethodValue(Designer.CreateMethod(AValue, GetTypeData(GetPropType)));
  1393.     if NewMethod then Designer.ShowMethod(AValue);
  1394.   end;
  1395. end;
  1396.  
  1397. { TFontNameProperty }
  1398.  
  1399. function TFontNameProperty.GetAttributes: TPropertyAttributes;
  1400. begin
  1401.   Result := [paMultiSelect, paValueList, paSortList, paRevertable];
  1402. end;
  1403.  
  1404. procedure TFontNameProperty.GetValues(Proc: TGetStrProc);
  1405. var
  1406.   I: Integer;
  1407. begin
  1408.   for I := 0 to Screen.Fonts.Count - 1 do Proc(Screen.Fonts[I]);
  1409. end;
  1410.  
  1411.  
  1412. { TMPFilenameProperty }
  1413.  
  1414. procedure TMPFilenameProperty.Edit;
  1415. var
  1416.   MPFileOpen: TOpenDialog;
  1417. begin
  1418.   MPFileOpen := TOpenDialog.Create(Application);
  1419.   MPFileOpen.Filename := GetValue;
  1420.   MPFileOpen.Filter := LoadStr(SMPOpenFilter);
  1421.   MPFileOpen.HelpContext := hcDMediaPlayerOpen;
  1422.   MPFileOpen.Options := MPFileOpen.Options + [ofShowHelp, ofPathMustExist,
  1423.     ofFileMustExist];
  1424.   try
  1425.     if MPFileOpen.Execute then SetValue(MPFileOpen.Filename);
  1426.   finally
  1427.     MPFileOpen.Free;
  1428.   end;
  1429. end;
  1430.  
  1431. function TMPFilenameProperty.GetAttributes: TPropertyAttributes;
  1432. begin
  1433.   Result := [paDialog, paRevertable];
  1434. end;
  1435.  
  1436. { TColorProperty }
  1437.  
  1438. procedure TColorProperty.Edit;
  1439. var
  1440.   ColorDialog: TColorDialog;
  1441.   IniFile: TIniFile;
  1442.  
  1443.   procedure GetCustomColors;
  1444.   begin
  1445.     IniFile := TIniFile.Create('DELPHI32.INI');
  1446.     try
  1447.       IniFile.ReadSectionValues(LoadStr(SCustomColors),
  1448.         ColorDialog.CustomColors);
  1449.     except
  1450.       { Ignore errors reading values }
  1451.     end;
  1452.   end;
  1453.  
  1454.   procedure SaveCustomColors;
  1455.   var
  1456.     I, P: Integer;
  1457.     S: string;
  1458.   begin
  1459.     if IniFile <> nil then
  1460.       with ColorDialog do
  1461.         for I := 0 to CustomColors.Count - 1 do
  1462.         begin
  1463.           S := CustomColors.Strings[I];
  1464.           P := Pos('=', S);
  1465.           if P <> 0 then
  1466.           begin
  1467.             S := Copy(S, 1, P - 1);
  1468.             IniFile.WriteString(LoadStr(SCustomColors), S,
  1469.               CustomColors.Values[S]);
  1470.           end;
  1471.         end;
  1472.   end;
  1473.  
  1474. begin
  1475.   IniFile := nil;
  1476.   ColorDialog := TColorDialog.Create(Application);
  1477.   try
  1478.     GetCustomColors;
  1479.     ColorDialog.Color := GetOrdValue;
  1480.     ColorDialog.HelpContext := hcDColorEditor;
  1481.     ColorDialog.Options := [cdShowHelp];
  1482.     if ColorDialog.Execute then SetOrdValue(ColorDialog.Color);
  1483.     SaveCustomColors;
  1484.   finally
  1485.     if IniFile <> nil then IniFile.Free;
  1486.     ColorDialog.Free;
  1487.   end;
  1488. end;
  1489.  
  1490. function TColorProperty.GetAttributes: TPropertyAttributes;
  1491. begin
  1492.   Result := [paMultiSelect, paDialog, paValueList, paRevertable];
  1493. end;
  1494.  
  1495. function TColorProperty.GetValue: string;
  1496. begin
  1497.   Result := ColorToString(TColor(GetOrdValue));
  1498. end;
  1499.  
  1500. procedure TColorProperty.GetValues(Proc: TGetStrProc);
  1501. begin
  1502.   GetColorValues(Proc);
  1503. end;
  1504.  
  1505. procedure TColorProperty.SetValue(const Value: string);
  1506. var
  1507.   NewValue: Longint;
  1508. begin
  1509.   if IdentToColor(Value, NewValue) then
  1510.     SetOrdValue(NewValue)
  1511.   else inherited SetValue(Value);
  1512. end;
  1513.  
  1514. { TCursorProperty }
  1515.  
  1516. function TCursorProperty.GetAttributes: TPropertyAttributes;
  1517. begin
  1518.   Result := [paMultiSelect, paValueList, paSortList, paRevertable];
  1519. end;
  1520.  
  1521. function TCursorProperty.GetValue: string;
  1522. begin
  1523.   Result := CursorToString(TCursor(GetOrdValue));
  1524. end;
  1525.  
  1526. procedure TCursorProperty.GetValues(Proc: TGetStrProc);
  1527. begin
  1528.   GetCursorValues(Proc);
  1529. end;
  1530.  
  1531. procedure TCursorProperty.SetValue(const Value: string);
  1532. var
  1533.   NewValue: Longint;
  1534. begin
  1535.   if IdentToCursor(Value, NewValue) then
  1536.     SetOrdValue(NewValue)
  1537.   else inherited SetValue(Value);
  1538. end;
  1539.  
  1540. { TFontProperty }
  1541.  
  1542. procedure TFontProperty.Edit;
  1543. var
  1544.   FontDialog: TFontDialog;
  1545. begin
  1546.   FontDialog := TFontDialog.Create(Application);
  1547.   try
  1548.     FontDialog.Font := TFont(GetOrdValue);
  1549.     FontDialog.HelpContext := hcDFontEditor;
  1550.     FontDialog.Options := FontDialog.Options + [fdShowHelp, fdForceFontExist];
  1551.     if FontDialog.Execute then SetOrdValue(Longint(FontDialog.Font));
  1552.   finally
  1553.     FontDialog.Free;
  1554.   end;
  1555. end;
  1556.  
  1557. function TFontProperty.GetAttributes: TPropertyAttributes;
  1558. begin
  1559.   Result := [paMultiSelect, paSubProperties, paDialog, paReadOnly];
  1560. end;
  1561.  
  1562. { TModalResultProperty }
  1563.  
  1564. const
  1565.   ModalResults: array[mrNone..mrNo] of string = (
  1566.     'mrNone',
  1567.     'mrOk',
  1568.     'mrCancel',
  1569.     'mrAbort',
  1570.     'mrRetry',
  1571.     'mrIgnore',
  1572.     'mrYes',
  1573.     'mrNo');
  1574.  
  1575. function TModalResultProperty.GetAttributes: TPropertyAttributes;
  1576. begin
  1577.   Result := [paMultiSelect, paValueList, paRevertable];
  1578. end;
  1579.  
  1580. function TModalResultProperty.GetValue: string;
  1581. var
  1582.   CurValue: Longint;
  1583. begin
  1584.   CurValue := GetOrdValue;
  1585.   case CurValue of
  1586.     Low(ModalResults)..High(ModalResults):
  1587.       Result := ModalResults[CurValue];
  1588.   else
  1589.     Result := IntToStr(CurValue);
  1590.   end;
  1591. end;
  1592.  
  1593. procedure TModalResultProperty.GetValues(Proc: TGetStrProc);
  1594. var
  1595.   I: Integer;
  1596. begin
  1597.   for I := Low(ModalResults) to High(ModalResults) do Proc(ModalResults[I]);
  1598. end;
  1599.  
  1600. procedure TModalResultProperty.SetValue(const Value: string);
  1601. var
  1602.   I: Integer;
  1603. begin
  1604.   if Value = '' then
  1605.   begin
  1606.     SetOrdValue(0);
  1607.     Exit;
  1608.   end;
  1609.   for I := Low(ModalResults) to High(ModalResults) do
  1610.     if CompareText(ModalResults[I], Value) = 0 then
  1611.     begin
  1612.       SetOrdValue(I);
  1613.       Exit;
  1614.     end;
  1615.   inherited SetValue(Value);
  1616. end;
  1617.  
  1618. { TShortCutProperty }
  1619.  
  1620. const
  1621.   ShortCuts: array[0..82] of TShortCut = (
  1622.     scNone,
  1623.     Byte('A') or scCtrl,
  1624.     Byte('B') or scCtrl,
  1625.     Byte('C') or scCtrl,
  1626.     Byte('D') or scCtrl,
  1627.     Byte('E') or scCtrl,
  1628.     Byte('F') or scCtrl,
  1629.     Byte('G') or scCtrl,
  1630.     Byte('H') or scCtrl,
  1631.     Byte('I') or scCtrl,
  1632.     Byte('J') or scCtrl,
  1633.     Byte('K') or scCtrl,
  1634.     Byte('L') or scCtrl,
  1635.     Byte('M') or scCtrl,
  1636.     Byte('N') or scCtrl,
  1637.     Byte('O') or scCtrl,
  1638.     Byte('P') or scCtrl,
  1639.     Byte('Q') or scCtrl,
  1640.     Byte('R') or scCtrl,
  1641.     Byte('S') or scCtrl,
  1642.     Byte('T') or scCtrl,
  1643.     Byte('U') or scCtrl,
  1644.     Byte('V') or scCtrl,
  1645.     Byte('W') or scCtrl,
  1646.     Byte('X') or scCtrl,
  1647.     Byte('Y') or scCtrl,
  1648.     Byte('Z') or scCtrl,
  1649.     VK_F1,
  1650.     VK_F2,
  1651.     VK_F3,
  1652.     VK_F4,
  1653.     VK_F5,
  1654.     VK_F6,
  1655.     VK_F7,
  1656.     VK_F8,
  1657.     VK_F9,
  1658.     VK_F10,
  1659.     VK_F11,
  1660.     VK_F12,
  1661.     VK_F1 or scCtrl,
  1662.     VK_F2 or scCtrl,
  1663.     VK_F3 or scCtrl,
  1664.     VK_F4 or scCtrl,
  1665.     VK_F5 or scCtrl,
  1666.     VK_F6 or scCtrl,
  1667.     VK_F7 or scCtrl,
  1668.     VK_F8 or scCtrl,
  1669.     VK_F9 or scCtrl,
  1670.     VK_F10 or scCtrl,
  1671.     VK_F11 or scCtrl,
  1672.     VK_F12 or scCtrl,
  1673.     VK_F1 or scShift,
  1674.     VK_F2 or scShift,
  1675.     VK_F3 or scShift,
  1676.     VK_F4 or scShift,
  1677.     VK_F5 or scShift,
  1678.     VK_F6 or scShift,
  1679.     VK_F7 or scShift,
  1680.     VK_F8 or scShift,
  1681.     VK_F9 or scShift,
  1682.     VK_F10 or scShift,
  1683.     VK_F11 or scShift,
  1684.     VK_F12 or scShift,
  1685.     VK_F1 or scShift or scCtrl,
  1686.     VK_F2 or scShift or scCtrl,
  1687.     VK_F3 or scShift or scCtrl,
  1688.     VK_F4 or scShift or scCtrl,
  1689.     VK_F5 or scShift or scCtrl,
  1690.     VK_F6 or scShift or scCtrl,
  1691.     VK_F7 or scShift or scCtrl,
  1692.     VK_F8 or scShift or scCtrl,
  1693.     VK_F9 or scShift or scCtrl,
  1694.     VK_F10 or scShift or scCtrl,
  1695.     VK_F11 or scShift or scCtrl,
  1696.     VK_F12 or scShift or scCtrl,
  1697.     VK_INSERT,
  1698.     VK_INSERT or scShift,
  1699.     VK_INSERT or scCtrl,
  1700.     VK_DELETE,
  1701.     VK_DELETE or scShift,
  1702.     VK_DELETE or scCtrl,
  1703.     VK_BACK or scAlt,
  1704.     VK_BACK or scShift or scAlt);
  1705.  
  1706. function TShortCutProperty.GetAttributes: TPropertyAttributes;
  1707. begin
  1708.   Result := [paMultiSelect, paValueList, paRevertable];
  1709. end;
  1710.  
  1711. function TShortCutProperty.GetValue: string;
  1712. var
  1713.   CurValue: TShortCut;
  1714. begin
  1715.   CurValue := GetOrdValue;
  1716.   if CurValue = scNone then
  1717.     Result := LoadStr(srNone) else
  1718.     Result := ShortCutToText(CurValue);
  1719. end;
  1720.  
  1721. procedure TShortCutProperty.GetValues(Proc: TGetStrProc);
  1722. var
  1723.   I: Integer;
  1724. begin
  1725.   Proc(LoadStr(srNone));
  1726.   for I := 1 to High(ShortCuts) do Proc(ShortCutToText(ShortCuts[I]));
  1727. end;
  1728.  
  1729. procedure TShortCutProperty.SetValue(const Value: string);
  1730. var
  1731.   NewValue: TShortCut;
  1732. begin
  1733.   NewValue := 0;
  1734.   if (Value <> '') and (CompareText(Value, LoadStr(srNone)) <> 0) then
  1735.   begin
  1736.     NewValue := TextToShortCut(Value);
  1737.     if NewValue = 0 then
  1738.       raise EPropertyError.CreateRes(SInvalidPropertyValue);
  1739.   end;
  1740.   SetOrdValue(NewValue);
  1741. end;
  1742.  
  1743. { TTabOrderProperty }
  1744.  
  1745. function TTabOrderProperty.GetAttributes: TPropertyAttributes;
  1746. begin
  1747.   Result := [];
  1748. end;
  1749.  
  1750. { TCaptionProperty }
  1751.  
  1752. function TCaptionProperty.GetAttributes: TPropertyAttributes;
  1753. begin
  1754.   Result := [paMultiSelect, paAutoUpdate, paRevertable];
  1755. end;
  1756.  
  1757. { TPropInfoList }
  1758.  
  1759. type
  1760.   TPropInfoList = class
  1761.   private
  1762.     FList: PPropList;
  1763.     FCount: Integer;
  1764.     FSize: Integer;
  1765.     function Get(Index: Integer): PPropInfo;
  1766.   public
  1767.     constructor Create(Component: TComponent; Filter: TTypeKinds);
  1768.     destructor Destroy; override;
  1769.     function Contains(P: PPropInfo): Boolean;
  1770.     procedure Delete(Index: Integer);
  1771.     procedure Intersect(List: TPropInfoList);
  1772.     property Count: Integer read FCount;
  1773.     property Items[Index: Integer]: PPropInfo read Get; default;
  1774.   end;
  1775.  
  1776. constructor TPropInfoList.Create(Component: TComponent; Filter: TTypeKinds);
  1777. begin
  1778.   FCount := GetPropList(Component.ClassInfo, Filter, nil);
  1779.   FSize := FCount * SizeOf(Pointer);
  1780.   GetMem(FList, FSize);
  1781.   GetPropList(Component.ClassInfo, Filter, FList);
  1782. end;
  1783.  
  1784. destructor TPropInfoList.Destroy;
  1785. begin
  1786.   if FList <> nil then FreeMem(FList, FSize);
  1787. end;
  1788.  
  1789. function TPropInfoList.Contains(P: PPropInfo): Boolean;
  1790. var
  1791.   I: Integer;
  1792. begin
  1793.   for I := 0 to FCount - 1 do
  1794.     with FList^[I]^ do
  1795.       if (PropType = P^.PropType) and (CompareText(Name, P^.Name) = 0) then
  1796.       begin
  1797.         Result := True;
  1798.         Exit;
  1799.       end;
  1800.   Result := False;
  1801. end;
  1802.  
  1803. procedure TPropInfoList.Delete(Index: Integer);
  1804. begin
  1805.   Dec(FCount);
  1806.   if Index < FCount then
  1807.     Move(FList^[Index + 1], FList^[Index],
  1808.       (FCount - Index) * SizeOf(Pointer));
  1809. end;
  1810.  
  1811. function TPropInfoList.Get(Index: Integer): PPropInfo;
  1812. begin
  1813.   Result := FList^[Index];
  1814. end;
  1815.  
  1816. procedure TPropInfoList.Intersect(List: TPropInfoList);
  1817. var
  1818.   I: Integer;
  1819. begin
  1820.   for I := FCount - 1 downto 0 do
  1821.     if not List.Contains(FList^[I]) then Delete(I);
  1822. end;
  1823.  
  1824. { GetComponentProperties }
  1825.  
  1826. procedure RegisterPropertyEditor(PropertyType: PTypeInfo; ComponentClass: TClass;
  1827.   const PropertyName: string; EditorClass: TPropertyEditorClass);
  1828. var
  1829.   P: PPropertyClassRec;
  1830. begin
  1831.   New(P);
  1832.   P^.Next := PropertyClassList;
  1833.   P^.PropertyType := PropertyType;
  1834.   P^.ComponentClass := ComponentClass;
  1835.   P^.PropertyName := '';
  1836.   if Assigned(ComponentClass) then P^.PropertyName := PropertyName;
  1837.   P^.EditorClass := EditorClass;
  1838.   PropertyClassList := P;
  1839. end;
  1840.  
  1841. procedure RegisterPropertyMapper(Mapper: TPropertyMapperFunc);
  1842. var
  1843.   P: PPropertyMapperRec;
  1844. begin
  1845.   New(P);
  1846.   P^.Next := PropertyMapperList;
  1847.   P^.Mapper := Mapper;
  1848.   PropertyMapperList := P;
  1849. end;
  1850.  
  1851. function GetEditorClass(PropInfo: PPropInfo;
  1852.   Component: TComponent): TPropertyEditorClass;
  1853. var
  1854.   ComponentClass: TClass;
  1855.   PropType: PTypeInfo;
  1856.   P, C: PPropertyClassRec;
  1857.   M: PPropertyMapperRec;
  1858. begin
  1859.   M := PropertyMapperList;
  1860.   while M <> nil do
  1861.   begin
  1862.     Result := M^.Mapper(Component, PropInfo);
  1863.     if Result <> nil then Exit;
  1864.     M := M^.Next;
  1865.   end;
  1866.   ComponentClass := Component.ClassType;
  1867.   PropType := PropInfo^.PropType;
  1868.   P := PropertyClassList;
  1869.   C := nil;
  1870.   while P <> nil do
  1871.   begin
  1872.     if ((P^.PropertyType = PropType) or ((PropType^.Kind = tkClass) and
  1873.       (P^.PropertyType^.Kind = tkClass) and
  1874.       GetTypeData(PropType)^.ClassType.InheritsFrom(GetTypeData(P^.PropertyType)^.ClassType))) and
  1875.       ((P^.ComponentClass = nil) or (ComponentClass.InheritsFrom(P^.ComponentClass))) and
  1876.       ((P^.PropertyName = '') or (CompareText(PropInfo^.Name, P^.PropertyName) = 0)) then
  1877.       if (C = nil) or ((C^.ComponentClass = nil) and (P^.ComponentClass <> nil))
  1878.         or ((C^.PropertyName = '') and (P^.PropertyName <> '')) then C := P;
  1879.     P := P^.Next;
  1880.   end;
  1881.   if C <> nil then
  1882.     Result := C^.EditorClass else
  1883.     Result := PropClassMap[PropType^.Kind];
  1884. end;
  1885.  
  1886. procedure GetComponentProperties(Components: TComponentList;
  1887.   Filter: TTypeKinds; Designer: TFormDesigner; Proc: TGetPropEditProc);
  1888. var
  1889.   I, J, CompCount: Integer;
  1890.   Component: TComponent;
  1891.   CompType: TClass;
  1892.   Candidates: TPropInfoList;
  1893.   PropLists: TList;
  1894.   Editor: TPropertyEditor;
  1895.   PropInfo: PPropInfo;
  1896.   AddEditor: Boolean;
  1897. begin
  1898.   if (Components = nil) or (Components.Count = 0) then Exit;
  1899.   CompCount := Components.Count;
  1900.   Component := Components[0];
  1901.   CompType := Component.ClassType;
  1902.   Candidates := TPropInfoList.Create(Components[0], Filter);
  1903.   try
  1904.     for I := Candidates.Count - 1 downto 0 do
  1905.     begin
  1906.       PropInfo := Candidates[I];
  1907.       Editor := GetEditorClass(PropInfo, Component).Create(Designer, 1);
  1908.       try
  1909.         Editor.SetPropEntry(0, Components[0], PropInfo);
  1910.         Editor.Initialize;
  1911.         with PropInfo^ do
  1912.           if (GetProc = nil) or ((PropType^.Kind <> tkClass) and
  1913.             (SetProc = nil)) or ((CompCount > 1) and
  1914.             not (paMultiSelect in Editor.GetAttributes)) or
  1915.             not Editor.ValueAvailable then
  1916.             Candidates.Delete(I);
  1917.       finally
  1918.         Editor.Free;
  1919.       end;
  1920.     end;
  1921.     PropLists := TList.Create;
  1922.     try
  1923.       PropLists.Capacity := CompCount;
  1924.       for I := 0 to CompCount - 1 do
  1925.         PropLists.Add(TPropInfoList.Create(Components[I], Filter));
  1926.       for I := 0 to CompCount - 1 do
  1927.         Candidates.Intersect(TPropInfoList(PropLists[I]));
  1928.       for I := 0 to CompCount - 1 do
  1929.         TPropInfoList(PropLists[I]).Intersect(Candidates);
  1930.       for I := 0 to Candidates.Count - 1 do
  1931.       begin
  1932.         Editor := GetEditorClass(Candidates[I],
  1933.           Component).Create(Designer, CompCount);
  1934.         try
  1935.           AddEditor := True;
  1936.           for J := 0 to CompCount - 1 do
  1937.           begin
  1938.             if (Components[J].ClassType <> CompType) and
  1939.               (GetEditorClass(TPropInfoList(PropLists[J])[I],
  1940.                 Components[J]) <> Editor.ClassType) then
  1941.             begin
  1942.               AddEditor := False;
  1943.               Break;
  1944.             end;
  1945.             Editor.SetPropEntry(J, Components[J],
  1946.               TPropInfoList(PropLists[J])[I]);
  1947.           end;
  1948.         except
  1949.           Editor.Free;
  1950.           raise;
  1951.         end;
  1952.         if AddEditor then
  1953.         begin
  1954.           Editor.Initialize;
  1955.           if Editor.ValueAvailable then
  1956.             Proc(Editor) else
  1957.             Editor.Free;
  1958.         end
  1959.         else Editor.Free;
  1960.       end;
  1961.     finally
  1962.       for I := 0 to PropLists.Count - 1 do TPropInfoList(PropLists[I]).Free;
  1963.       PropLists.Free;
  1964.     end;
  1965.   finally
  1966.     Candidates.Free;
  1967.   end;
  1968. end;
  1969.  
  1970. { RegisterComponentEditor }
  1971.  
  1972. type
  1973.   PComponentClassRec = ^TComponentClassRec;
  1974.   TComponentClassRec = record
  1975.     Next: PComponentClassRec;
  1976.     ComponentClass: TComponentClass;
  1977.     EditorClass: TComponentEditorClass;
  1978.   end;
  1979.  
  1980. var
  1981.   ComponentClassList: PComponentClassRec = nil;
  1982.  
  1983. procedure RegisterComponentEditor(ComponentClass: TComponentClass;
  1984.   ComponentEditor: TComponentEditorClass);
  1985. var
  1986.   P: PComponentClassRec;
  1987. begin
  1988.   New(P);
  1989.   P^.Next := ComponentClassList;
  1990.   P^.ComponentClass := ComponentClass;
  1991.   P^.EditorClass := ComponentEditor;
  1992.   ComponentClassList := P;
  1993. end;
  1994.  
  1995. { GetComponentEditor }
  1996.  
  1997. function GetComponentEditor(Component: TComponent;
  1998.   Designer: TFormDesigner): TComponentEditor;
  1999. var
  2000.   P: PComponentClassRec;
  2001.   ComponentClass: TComponentClass;
  2002.   EditorClass: TComponentEditorClass;
  2003. begin
  2004.   P := ComponentClassList;
  2005.   ComponentClass := TComponent;
  2006.   EditorClass := TDefaultEditor;
  2007.   while P <> nil do
  2008.   begin
  2009.     if (Component is P^.ComponentClass) and
  2010.       (P^.ComponentClass.InheritsFrom(ComponentClass)) then
  2011.     begin
  2012.       EditorClass := P^.EditorClass;
  2013.       ComponentClass := P^.ComponentClass;
  2014.     end;
  2015.     P := P^.Next;
  2016.   end;
  2017.   Result := EditorClass.Create(Component, Designer);
  2018. end;
  2019.  
  2020. { TComponentEditor }
  2021.  
  2022. constructor TComponentEditor.Create(AComponent: TComponent; ADesigner: TFormDesigner);
  2023. begin
  2024.   inherited Create;
  2025.   FComponent := AComponent;
  2026.   FDesigner := ADesigner;
  2027. end;
  2028.  
  2029. procedure TComponentEditor.Edit;
  2030. begin
  2031.   if GetVerbCount > 0 then ExecuteVerb(0);
  2032. end;
  2033.  
  2034. function TComponentEditor.GetVerbCount: Integer;
  2035. begin
  2036.   Result := 0;
  2037. end;
  2038.  
  2039. function TComponentEditor.GetVerb(Index: Integer): string;
  2040. begin
  2041. end;
  2042.  
  2043. procedure TComponentEditor.ExecuteVerb(Index: Integer);
  2044. begin
  2045. end;
  2046.  
  2047. procedure TComponentEditor.Copy;
  2048. begin
  2049. end;
  2050.  
  2051. { TDefaultEditor }
  2052.  
  2053. procedure TDefaultEditor.CheckEdit(PropertyEditor: TPropertyEditor);
  2054. var
  2055.   FreeEditor: Boolean;
  2056. begin
  2057.   FreeEditor := True;
  2058.   try
  2059.     if FContinue then EditProperty(PropertyEditor, FContinue, FreeEditor);
  2060.   finally
  2061.     if FreeEditor then PropertyEditor.Free;
  2062.   end;
  2063. end;
  2064.  
  2065. procedure TDefaultEditor.EditProperty(PropertyEditor: TPropertyEditor;
  2066.   var Continue, FreeEditor: Boolean);
  2067. var
  2068.   PropName: string;
  2069.   BestName: string;
  2070.  
  2071.   procedure ReplaceBest;
  2072.   begin
  2073.     FBest.Free;
  2074.     FBest := PropertyEditor;
  2075.     if FFirst = FBest then FFirst := nil;
  2076.     FreeEditor := False;
  2077.   end;
  2078.  
  2079. begin
  2080.   if not Assigned(FFirst) and (PropertyEditor is TMethodProperty) then
  2081.   begin
  2082.     FreeEditor := False;
  2083.     FFirst := PropertyEditor;
  2084.   end;
  2085.   PropName := PropertyEditor.GetName;
  2086.   BestName := '';
  2087.   if Assigned(FBest) then BestName := FBest.GetName;
  2088.   if CompareText(PropName, 'ONCREATE') = 0 then
  2089.     ReplaceBest
  2090.   else if CompareText(BestName, 'ONCREATE') <> 0 then
  2091.     if CompareText(PropName, 'ONCHANGE') = 0 then
  2092.       ReplaceBest
  2093.     else if CompareText(BestName, 'ONCHANGE') <> 0 then
  2094.       if CompareText(PropName, 'ONCLICK') = 0 then
  2095.         ReplaceBest;
  2096. end;
  2097.  
  2098. procedure TDefaultEditor.Edit;
  2099. var
  2100.   Components: TComponentList;
  2101. begin
  2102.   Components := TComponentList.Create;
  2103.   try
  2104.     FContinue := True;
  2105.     Components.Add(Component);
  2106.     FFirst := nil;
  2107.     FBest := nil;
  2108.     try
  2109.       GetComponentProperties(Components, tkAny, Designer, CheckEdit);
  2110.       if FContinue then
  2111.         if Assigned(FBest) then
  2112.           FBest.Edit
  2113.         else if Assigned(FFirst) then
  2114.           FFirst.Edit;
  2115.     finally
  2116.       FFirst.Free;
  2117.       FBest.Free;
  2118.     end;
  2119.   finally
  2120.     Components.Free;
  2121.   end;
  2122. end;
  2123.  
  2124. end.
  2125.