The Forms1 sample uses a control array for the text fields. The first Text Control, the one which you see when you start the program, is placed on the form at design time. More controls are created when you click on an empty area of the form. These controls are created dynamically with the Delphi Create method. Then they are assigned initial values.
procedure TForm1.FormMouseDown(Sender: TObject; Button: TMouseButton; Shift: TShiftState; X, Y: Integer); begin MaxID := MaxID + 1; TX := TTXTextControl.Create(Form1); TX.Parent := Form1; TX.Top := Y; TX.Left := X; TX.Width := TXTextControl1.Width; TX.Height := TXTextControl1.Height; TX.Name := 'TXTextControl' + InttoStr(MaxID); TX.SizeMode := 3; // Move- and sizeable TX.BringtoFront; TX.OnMouseDown := TXTextControl1MouseDown; end;
Clicking on an existing text field brings it to the front. This is done by changing the Z order when a Click event has occurred:
procedure TForm1.TXTextControl1MouseDown(Sender: TObject; Button: TMouseButton; Shift: TShiftState; X, Y: Integer); begin TTXTextControl(Sender).BringtoFront; end;
The global variable MaxID counts the total number of controls; It is initialized to a value of 1 when the form is loaded.
Moving and resizing the controls is done by Text Control itself. To enable these functions, the SizeMode property must be set to 3 - Move and Sizeable.