Changing the Name of a Component

From RAD Studio
Jump to: navigation, search

Go Up to What Is an Object


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 Name property of the form in the Object Inspector, the new name is automatically reflected in the .dfm or .fmx file of a form (which you usually do not edit manually) and in the source code that the IDE generates:

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:

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

See Also