FindComponent (C++)

From Appmethod Code Examples
Jump to: navigation, search

Description

The following example creates 20 edit boxes, using FindComponent with the edit box name to access each newly created edit box.

Code

const int EditBoxCount = 20;
const int LeftCoordinate = 10;
TEdit* pe[20];

__fastcall TForm1::TForm1(TComponent* Owner)
  : TForm(Owner)
{
    const char* pszNamePrefix = "MyEdit";
    for (int i=0;i<EditBoxCount;i++)
    {
        // These objects will be cleaned up by their owner (this).
        pe[i] = new TEdit(this);
        pe[i]->Name = pszNamePrefix + IntToStr(i+1);
        pe[i]->Left = LeftCoordinate;
        pe[i]->Top = i*EditBoxCount;
        pe[i]->Parent = this;
    }
}

Uses