Such a task ...

Is it possible to create a dynamic object / component (for example, a TImage ) so that it is at the bottom of all other components.

Those. It is created on top of all other components. Is it possible to fix it so that it is created below?

And also: how to clean (roughly speaking, remove) dynamic components from a variable, if there are a lot of them?

  • What do you mean by> clean (roughly speaking, remove) dynamic components "? - Nofate

2 answers 2

I am working with dynamics now, so I’ll just drop the example code:

  var LLabelArray : array of TLabel; LEditButtonArray : array of TButton; LDeleteButtonArray : array of TButton; i,z: integer; str: TStringList; Sender: TObject; begin // отрисовка динамических объектов // обнуляем переменную, отвечающую за позицию объекта z:= 0; // создаем стринглист str:= TStringList.Create; // читаем секцию и кидаем ее значени MainForm.CalendarIni.ReadSectionValues(DateToStr(MonthCalendar1.Date), str); // Если массивы не пустые, то if (Length(LLabelArray) <> 0) and (Length(LEditButtonArray) <> 0) and (Length(LDeleteButtonArray) <> 0)then begin // удаляем объекты for I := 0 to Length(LLabelArray) -1 do begin LLabelArray[i].Free; end; for I := 0 to Length(LEditButtonArray) -1 do begin LEditButtonArray[i].Free; end; for I := 0 to Length(LDeleteButtonArray) -1 do begin LDeleteButtonArray[i].Free; end; // очищаем массивы SetLength(LLabelArray, 0); SetLength(LEditButtonArray, 0); SetLength(LDeleteButtonArray, 0); end; // Заполняем массив объектами for I := 0 to str.Count -1 do // Если строка не пустая, то создаем объект if MainForm.CalendarIni.ReadString(Copy(str[i], 1, Pos('=', str[i])-1), 'Caption', '') <> '=' then // Если в строке текст, то создаем лэйбл if MainForm.CalendarIni.ReadString(Copy(str[i], 1, Pos('=', str[i])-1), 'Caption', '') <> '-' then begin // ============= РИСУЕМ КНОПКУ РЕДАКТИРОВАНИЯ =========== // Увеличиваем размер массива на 1 SetLength(LEditButtonArray, Length(LEditButtonArray) + 1); // Создаем объект LEditButtonArray[Length(LEditButtonArray) - 1] := TButton.Create(Owner); // настраиваем его свойства // устанавливаем родителя LEditButtonArray[Length(LEditButtonArray) - 1].Parent := Panel1; // отступ слева LEditButtonArray[Length(LEditButtonArray) - 1].Left := self.Lleft; // отступ сверху LEditButtonArray[Length(LEditButtonArray) - 1].Top := 25 * z + self.Ltop; // длина и ширина LEditButtonArray[Length(LEditButtonArray) - 1].Width := 25; LEditButtonArray[Length(LEditButtonArray) - 1].Height := 20; // вписываем в тэг номер объекта LEditButtonArray[Length(LEditButtonArray) - 1].Tag := z; // Обработчик нажатия LEditButtonArray[Length(LEditButtonArray) - 1].OnClick := self.EditButtonOnClick; // Caption LEditButtonArray[Length(LEditButtonArray) - 1].Caption := 'Ред'; // ============= РИСУЕМ КНОПКУ УДАЛЕНИЯ =========== // Увеличиваем размер массива на 1 SetLength(LDeleteButtonArray, Length(LDeleteButtonArray) + 1); // Создаем объект LDeleteButtonArray[Length(LDeleteButtonArray) - 1] := TButton.Create(Owner); // настраиваем его свойства // устанавливаем родителя LDeleteButtonArray[Length(LDeleteButtonArray) - 1].Parent := Panel1; // отступ слева LDeleteButtonArray[Length(LDeleteButtonArray) - 1].Left := self.Lleft + 30; // отступ сверху LDeleteButtonArray[Length(LDeleteButtonArray) - 1].Top := 25 * z + self.Ltop; // длина и ширина LDeleteButtonArray[Length(LDeleteButtonArray) - 1].Width := 25; LDeleteButtonArray[Length(LDeleteButtonArray) - 1].Height := 20; // вписываем в тэг номер объекта LDeleteButtonArray[Length(LDeleteButtonArray) - 1].Tag := z; // Caption LDeleteButtonArray[Length(LDeleteButtonArray) - 1].Caption := 'Уд'; // Обработчик нажатия LDeleteButtonArray[Length(LDeleteButtonArray) - 1].OnClick := self.DeleteButtonOnClick; // ============= РИСУЕМ ЛЭЙБЛЫ ============ // Увеличиваем размер массива на 1 SetLength(LLabelArray, Length(LLabelArray) + 1); // Создаем объект LLabelArray[Length(LLabelArray) - 1] := TLabel.Create(Owner); // настраиваем его свойства LLabelArray[Length(LLabelArray) - 1].Parent := Panel3; LLabelArray[Length(LLabelArray) - 1].Left := self.Lleft + 10; LLabelArray[Length(LLabelArray) - 1].Top := 25 * z + self.Ltop; LLabelArray[Length(LLabelArray) - 1].Caption := MainForm.CalendarIni.ReadString(DateToStr(MonthCalendar1.Date), Copy(str[i], 1, Pos('=', str[i])-1), ''); // Увеличиваем z inc(z); end; end; 
  • one
    Throw a thought: lean on with ... do , greatly increase readability. Well, or at least short variable names at the time of filling the gap: EditButton: = TButton.Create (Owner); EditButton.Parent: = Panel1; EditButton.Left: = self.Lleft; EditButton.Top: = 25 * z + self.Ltop; EditButton.Width: = 25; EditButton.Height: = 20; EditButton.Tag: = z; EditButton.OnClick: = self.EditButtonOnClick; EditButton.Caption: = 'Ed'; LEditButtonArray [Length (LEditButtonArray) - 1]: = EditButton; - Nofate
  • This is the first experience. We are developing :) - teanYCH

To place a component behind all others within a container, use:

 Image1.SendToBack; 

To pull forward:

 Image1.BringToFront;