Getting value from Edit to work with region

I needed to divide the picture into sectors and count the number of black dots in each of them. I use regions for this. Can I do this with the Edit input field somehow?

HRGN region [n];

HRGN requires a constant value like

const n = 35;

Please, help if it is possible to somehow link HRGN with Edit, for example, if Edit is set as follows:

int n = Edit1-> Text.ToIntDef (0);

Answer

I think you are asking how to allocate an array using a TEdit to specify the array’s count, is that right?

Consider using T(C)SpinEdit instead of TEdit for numeric input.

You can allocate an array dynamically at runtime using new[]:

HRGN *region = NULL;
...
int n = Edit1->Text.ToInt(); // or SpinEdit1->Value
region = new HRGN[n];
// use region as needed...
delete[] region;

Or better, use std::vector, or System::DynamicArray, instead:

#include <vector>
std::vector<HRGN> region;
...
int n = Edit1->Text.ToInt(); // or SpinEdit1->Value
region.resize(n);
// use region as needed...
// freed automatically when out of scope...
#include <sysdyn.h>
DynamicArray<HRGN> region;
...
int n = Edit1-> Text.ToInt(); // or SpinEdit1->Value
region.Length = n;
// use region as needed...
// freed automatically when out of scope...