Question

Whatever component that will be created in c++ builder will be assigned TComponentName. For example when I create a form and assign it MyWidget it then the class that inherits TForm gets class TMyWidget : TForm{} form. With spy++ like inspectors you can see registered class names of your apps.

Concerning this my question is the following.

  • Is it possible at all and then how to create our forms, components with our desired name(excluding prefix T)?

The way I did it I created VCL Forms App and saved it. Then replaced TForm1 with my own desired classname, say, in my case WidgetCl0x01 in the .h,.dfm,project source file in __classid() arg but there was compilation and linking problems!

Show me directions on how to achieve this not just by changing VCL source !

Was it helpful?

Solution

You can override the virtual CreateParams() method to change the classname that is assigned to the HWND that is allocated for the TForm window, eg:

void __fastcall TMyWidget::CreateParams(TCreateParams &Params)
{
    TForm::CreateParams(Params)
    StrLCopy(Params.WinClassName, _D("WidgetCl0x01"), (sizeof(Params.WinClassName) / sizeof(Char)) - 1);
}

Use the Name property in the Object Inspector to change the class name of the TForm class itself in your code, don't try to adjust it by name. Just know that it will always be prefixed with a T, you cannot avoid that unless you disable the TForm's DFM and create all of its content by hand in code, then the classname will not matter.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top