Kreirati komponte tipa TEdit, za dati sql text ,pri tome se misli na text tipa select* from + tabela
Sledecim kodom se kreiraju editi,ali problem nastaje kada se menjaju tabele,stari editi se ne brisu a novi se kreiraju
evo kodova kojima sam napravio edite i labele..
Kako da resim problem?
procedure TForm1.CreateFilter(Text:String;pnl:TPanel);
var
i:Integer;
ed:TEdit;
lbl:TLabel;
Compom:TComponent;
begin
SimpleDataSet1.Open;
for i := 0 to SimpleDataSet1.FieldCount - 1 do
begin
Compom := pnl.FindComponent('ed'+SimpleDataSet1.Fields[i].DisplayName);
if Compom <> nil then
Compom.Free;
//Prvi malo elegantniji nacin
with TEdit.Create(pnl) do
begin
Parent := pnl;
Left := 10;
Height := 20;
Top := Height * i + 20;
Name :='ed' + SimpleDataSet1.Fields[i].DisplayName;
Text := '';
end;
with TLabel.Create(pnl) do
begin
Parent := pnl;
Left := 10;
Height := 20;
Top := Height * i;
Caption := SimpleDataSet1.Fields[i].DisplayLabel;
end;
{ Drugi nacin
ed := TEdit.Create(pnl);
with ed do
begin
Parent := pnl;
Left := 10;
Height := 20;
Top := Height * i + 20;
Name :='ed' + SimpleDataSet1.Fields[i].DisplayName;
Text := '';
end;
lbl := TLabel.Create(pnl);
with lbl do
begin
Parent := pnl;
Left := 10;
Height := 20;
Top := Height * i;
Caption := SimpleDataSet1.Fields[i].DisplayLabel;
end; }
end;
end;
procedure TForm1.FormCreate(Sender: TObject);
begin
SQLConnection1.GetTableNames(ComboBox1.Items);
end;
procedure TForm1.OpenDataSet;
var
TD:TTransactionDesc;
SqlText,ObjName:String;
begin
TD.TransactionID := 1;
TD.IsolationLevel := xilREADCOMMITTED;
SqlText := 'select * from $ObjName$';
ObjName := ComboBox1.Text;
SqlText := StringReplace(SqlText,'$ObjName$',ObjName,[]);
SimpleDataSet1.Close;
SimpleDataSet1.DataSet.CommandText := SqlText;
SQLConnection1.StartTransaction(TD);
SimpleDataSet1.Open;
SQLConnection1.Commit(TD);
cReateFilter(SqlText,pnlFilter);
end;
Dakle kreira nove ali ne brise stare?