1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143
| unit Unit1;
interface
uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
StdCtrls, Buttons;
type
TForm1 = class(TForm)
ScrollBox1 : TScrollBox;
BtnManipuler : TButton;
BtnCreer : TButton;
procedure FormCreate(Sender: TObject);
procedure BtnManipulerClick(Sender: TObject);
procedure BtnCreerClick(Sender: TObject);
private
public
end;
TElement = record
Id: byte; { $01: ComboBox; $02: Edit }
Name: string;
ValeurChaine: string;
end;
TListElem = array of TElement;
var
Form1: TForm1;
Liste: TListElem ;
implementation
{$R *.DFM}
procedure CreerListeElmt(var Liste: TListElem);
begin
SetLength(Liste, sizeof(TElement)*4);
{ Tcombobox 1 }
Liste[1].Id := $01;
Liste[1].Name := LowerCase('combo1');
Liste[1].ValeurChaine := '';
{ Tedit 1 }
Liste[2].Id := $02;
Liste[2].Name := LowerCase('edt1');
Liste[2].ValeurChaine := '';
{ Tedit 2 }
Liste[3].Id := $02;
Liste[3].Name := LowerCase('edt2');
Liste[3].ValeurChaine := '';
{ Tcombobox 2 }
Liste[4].Id := $01;
Liste[4].Name := LowerCase('combo2');
Liste[4].ValeurChaine := '';
end;
procedure RemplirScrollBox(ScrollBox: TScrollBox; Liste: array of TElement);
var
I : integer;
CountCB, CountEDT: byte; { compteurs de composants: gère le positionnement vertical }
begin
CountCB := 0;
CountEDT := 0;
while ScrollBox.ControlCount > 0 do
ScrollBox.Controls[0].Free;
for I := Low(Liste) to High(Liste) do
begin
Case Liste[i].Id of
$01:
begin
with TComboBox.Create(ScrollBox) do
begin
Parent := ScrollBox;
Left := 10;
Top := 10 + 24*CountCB;
Width := 200;
Height := 16;
Name := Liste[i].Name;
Items.Add(Liste[i].ValeurChaine);
Visible := True;
Inc(CountCB);
end;
end;
$02:
begin
with TEdit.Create(ScrollBox) do
begin
Parent := ScrollBox;
Left := 220;
Top := 10 + 24*CountEDT;
Width := ScrollBox.Width-230; // la largeur restante
Name := Liste[i].Name;
Text := Liste[i].ValeurChaine;
Visible := True;
Inc(CountEDT);
end;
end;
else
end;
end;
end;
procedure TForm1.FormCreate(Sender: TObject);
begin
CreerListeElmt(Liste);
end;
procedure TForm1.BtnCreerClick(Sender: TObject);
begin
RemplirScrollBox(Form1.ScrollBox1, Liste);
end;
procedure TForm1.BtnManipulerClick(Sender: TObject);
var
i: integer;
begin
{ récupère le 1er combobox }
with scrollBox1 do
begin
for i:= ComponentCount-1 downto 0 do
if ((Components[i] is TComboBox) and (TComboBox(Components[i]).Name = LowerCase('combo1'))) then
with Components[i] as TComboBox do
ItemIndex := Items.Add('Le texte de combo1');
end;
{ récupère le 2ème edit }
with scrollBox1 do
begin
for i:= ComponentCount-1 downto 0 do
if ((Components[i] is TEdit) and (TEdit(Components[i]).Name = LowerCase('edt2'))) then
with Components[i] as TEdit do
Text := 'Le texte de edt2';
end;
end;
end. |
Partager