RAD Studio |  |

Changing the Name of a Component
See Also
Collapse All

You should always use the Object Inspector to change the name of a component. For example, suppose you want to change a form's name from the default Form1 to a more descriptive name, such as ColorWindow. When you change the form's Name property in the Object Inspector, the new name is automatically reflected in the form's .dfm or .xfm file (which you usually don't edit manually) and in the source code that the IDE generates:

Copy Code

    unit Unit1;
    interface
    uses Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms, Dialogs;
    type
      TColorWindow = class(TForm){ Changed from TForm1 to TColorWindow }
        Button1: TButton;
        procedure Button1Click(Sender: TObject);
      private
        { Private declarations }
      public
        { Public declarations }
      end;
    var
      ColorWindow: TColorWindow;{ Changed from Form1 to ColorWindow }
    implementation
    {$R *.dfm}
    procedure TColorWindow.Button1Click(Sender: TObject);
    begin
      Form1.Color := clGreen;{ The reference to Form1 didn"t change! }
    end;
    end.

Note that the code in the OnClick event handler for the button hasn't changed. Because you wrote the code, you have to update it yourself and correct any references to the form:

Copy Code

    procedure TColorWindow.Button1Click(Sender: TObject);
    begin
      ColorWindow.Color := clGreen;
    end;

See Also

Examining a Delphi Object

What is an Object?

Copyright(C) 2009 Embarcadero Technologies, Inc. All Rights Reserved.
What do you think about this topic? Send feedback!