Zhile, evo resenja. Predlazem da prosirimo ideju tahi-ja sa array-em, ali malo poboljsanu:
Prvo, deklarisemo jedan tip record-a
Code:
TFilterEditRec = record
Edit: TEdit;
Label: TLabel;
FieldName: string;
end;
Drugo, deklarisemo array ovih record-a, ali ne kao global, vec u private delu forme
Code:
private
fEditArray: array of TFilterEditRec;
Trece, sledi prepravljena tvoja metoda za kreiranje edit-a
Code:
procedure TForm1.CreateFilter(Text:String;pnl:TPanel);
var
i:Integer;
ed:TEdit;
lbl:TLabel;
begin
SetLength(fEditArray, SimpleDataSet1.FieldCount);
for i := 0 to SimpleDataSet1.FieldCount - 1 do
begin
lbl := TLabel.Create(pnl);
with lbl do
begin
Parent := pnl;
Left := 10;
Top := 5;
if i > 0 then
begin
Compom := pnl.FindComponent('ed'+SimpleDataSet1.Fields[i-1].DisplayName);
if Compom <> nil then
Top := ed.Top + ed.Height + Height;
end;
Caption := SimpleDataSet1.Fields[i].DisplayLabel;
Name := 'lbl' + SimpleDataSet1.Fields[i].DisplayName;
end;
ed := TEdit.Create(pnl);
with ed do
begin
Parent := pnl;
Left := 10;
Height := 20;
Top := lbl.Top+lbl.Height + Height + 5;
Name := 'ed' + SimpleDataSet1.Fields[i].DisplayName;
Text := '';
end;
with fEditArray[i] do
begin
Edit := ed;
Label := lbl;
FieldName := SimpleDataSet1.Fields[i].FieldName; // ili DisplayName ?
end;
end;
end;
I cetvrto (poslednje) kako brisemo edite i labele pomocu ovog array-a
Code:
for i := 0 to length(fEditArray) - 1 do // moze i ovako: for i := low(fEditArray) to high(fEditArray) do
with fEditArray[i] do
begin
Edit.Free;
Label.Free;
end;
SetLength(fEditArray, 0); // ovo brise same record-e
To bi, mislim, bilo to.
Pozdrav
Rajko