Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Maintain my component's properties when they are changed?

I have a custom component with some published properties which have been used for a while in many projects. I want to make some particular changes to this component which requires removing these old properties and replacing them with new ones. Or otherwise, I'm not necessarily removing the properties, but let's say I just simply change the name of a property from PropName to MyPropName instead. Well, the next time any project using that component is opened, it will not be able to find PropName.

Is there any way to automate conversion of this? Or is this something people will have to do manually? What would be the proper way to maintain component property values when the names of those properties are changed?

And I mean just in the DFM code, not necessarily inside the source code.

like image 825
Jerry Dodge Avatar asked Jan 02 '12 21:01

Jerry Dodge


People also ask

How do I set the properties of a component?

This section describes the properties you can set for components. Open the component definition. Select File > Definition Properties. The Component Properties dialog box appears with the General tab active. Access the Component Properties dialog box.

Why are the properties of a COM+ object different from other objects?

Because the particular properties exposed can vary depending on what the item represents; that is, an item representing a component has different properties than one representing a COM+ application. Set any of these properties using a single generic property, the Value property, on COMAdminCatalogObject.

How do I get or set a specific property in comadmincatalogobject?

Set any of these properties using a single generic property, the Value property, on COMAdminCatalogObject. The Value property enables you to get or set any specific named property exposed by an item, returning a value for a named property when getting, and taking a name and value when setting.

How do I identify the applications associated with a component?

The Component Properties dialog box appears with the General tab active. Access the Component Properties dialog box. Enter a descriptive name for the component. Select the application to which this component belongs. This list is helpful to identify the applications that are associated with the component during the application development phase.


1 Answers

You can use the DefineProperties extension point to help migrate your .dfm files.

type
  TMyComponent = class(...)
  private
    procedure ReadPropName(Reader: TReader);
  protected
    procedure DefineProperties(Filer: TFiler); override;
  published
    property MyPropName: string read ... write ...;
  end;

procedure TMyComponent.DefineProperties(Filer: TFiler);
begin
  inherited;
  Filer.DefineProperty('PropName', ReadPropName, nil, False);
end;

procedure TMyComponent.ReadPropName(Reader: TReader);
begin
  MyPropName := Reader.ReadString;
end;

This will allow your new component to read in old .dfm files with the old property name. When the .dfm file is written again, the new property name will be used.

Note that such a technique results in the component being able to read .dfm files containing either the old property name or the new property name so you can migrate in a gradual fashion if you wish. Once you have migrated all your .dfm files then it would be worth removing such code for the sake of tidiness.

The Delphi documentation covers this subject area, albeit from a slightly different perspective, in the Storing and Loading Unpublished Properties section of the Component Writer's Guide.

like image 92
David Heffernan Avatar answered Oct 12 '22 22:10

David Heffernan