Elem kod Unita je:
Code:
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, DBXpress, DB, StdCtrls, SqlExpr, DBClient, SimpleDS, Grids,
DBGrids;
type
TForm1 = class(TForm)
DBGrid1: TDBGrid;
SimpleDataSet1: TSimpleDataSet;
SQLConnection1: TSQLConnection;
ComboBox1: TComboBox;
ComboBox2: TComboBox;
Button1: TButton;
DataSource1: TDataSource;
ComboBox3: TComboBox;
SimpleDataSet2: TSimpleDataSet;
procedure FormCreate(Sender: TObject);
procedure ComboBox1Change(Sender: TObject);
procedure Button1Click(Sender: TObject);
procedure ComboBox2Change(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
procedure TForm1.FormCreate(Sender: TObject);
begin
SQLConnection1.GetTableNames(ComboBox1.Items);
end;
procedure TForm1.ComboBox1Change(Sender: TObject);
begin
SQLConnection1.GetFieldNames(ComboBox1.Text,ComboBox2.Items);
SimpleDataSet1.Close;
SimpleDataSet1.DataSet.Close;
try
SimpleDataSet1.DataSet.CommandText:='';
SimpleDataSet1.DataSet.CommandType:=ctTable;
SimpleDataSet1.DataSet.CommandText:=ComboBox1.Text;
finally
SimpleDataSet1.DataSet.Open;
SimpleDataSet1.Open;
end;
end;
procedure TForm1.Button1Click(Sender: TObject);
begin
SimpleDataSet1.Close;
SimpleDataSet1.DataSet.Close;
try
SimpleDataSet1.DataSet.CommandType:=ctQuery;
SimpleDataSet1.DataSet.CommandText:='select * from '+Combobox1.text+' where '+ComboBox2.Text+' = '+QuotedStr(ComboBox3.Text);
finally
SimpleDataSet1.DataSet.Open;
SimpleDataSet1.Open;
end;
end;
procedure TForm1.ComboBox2Change(Sender: TObject);
var
i:integer;
begin
SimpleDataSet2.Close;
SimpleDataSet2.DataSet.Close;
try
SimpleDataSet2.DataSet.CommandType:=ctQuery;
SimpleDataSet2.DataSet.CommandText:='select '+ComboBox2.Text+' from '+ComboBox1.Text;
finally
SimpleDataSet2.DataSet.Open;
SimpleDataSet2.Open;
end;
ComboBox3.Items.BeginUpdate;
SimpleDataSet2.First;
try
while not SimpleDataSet2.Eof do
begin
for i:=0 to SimpleDataSet2.FieldCount-1 do
begin
ComboBox3.Items.Add(VarToStr(SimpleDataSet2.Fields[i].Value));
SimpleDataSet2.Next;
end;
end;
finally
ComboBox3.Items.EndUpdate;
end;
end;
end.
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, DBXpress, DB, StdCtrls, SqlExpr, DBClient, SimpleDS, Grids,
DBGrids;
type
TForm1 = class(TForm)
DBGrid1: TDBGrid;
SimpleDataSet1: TSimpleDataSet;
SQLConnection1: TSQLConnection;
ComboBox1: TComboBox;
ComboBox2: TComboBox;
Button1: TButton;
DataSource1: TDataSource;
ComboBox3: TComboBox;
SimpleDataSet2: TSimpleDataSet;
procedure FormCreate(Sender: TObject);
procedure ComboBox1Change(Sender: TObject);
procedure Button1Click(Sender: TObject);
procedure ComboBox2Change(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
procedure TForm1.FormCreate(Sender: TObject);
begin
SQLConnection1.GetTableNames(ComboBox1.Items);
end;
procedure TForm1.ComboBox1Change(Sender: TObject);
begin
SQLConnection1.GetFieldNames(ComboBox1.Text,ComboBox2.Items);
SimpleDataSet1.Close;
SimpleDataSet1.DataSet.Close;
try
SimpleDataSet1.DataSet.CommandText:='';
SimpleDataSet1.DataSet.CommandType:=ctTable;
SimpleDataSet1.DataSet.CommandText:=ComboBox1.Text;
finally
SimpleDataSet1.DataSet.Open;
SimpleDataSet1.Open;
end;
end;
procedure TForm1.Button1Click(Sender: TObject);
begin
SimpleDataSet1.Close;
SimpleDataSet1.DataSet.Close;
try
SimpleDataSet1.DataSet.CommandType:=ctQuery;
SimpleDataSet1.DataSet.CommandText:='select * from '+Combobox1.text+' where '+ComboBox2.Text+' = '+QuotedStr(ComboBox3.Text);
finally
SimpleDataSet1.DataSet.Open;
SimpleDataSet1.Open;
end;
end;
procedure TForm1.ComboBox2Change(Sender: TObject);
var
i:integer;
begin
SimpleDataSet2.Close;
SimpleDataSet2.DataSet.Close;
try
SimpleDataSet2.DataSet.CommandType:=ctQuery;
SimpleDataSet2.DataSet.CommandText:='select '+ComboBox2.Text+' from '+ComboBox1.Text;
finally
SimpleDataSet2.DataSet.Open;
SimpleDataSet2.Open;
end;
ComboBox3.Items.BeginUpdate;
SimpleDataSet2.First;
try
while not SimpleDataSet2.Eof do
begin
for i:=0 to SimpleDataSet2.FieldCount-1 do
begin
ComboBox3.Items.Add(VarToStr(SimpleDataSet2.Fields[i].Value));
SimpleDataSet2.Next;
end;
end;
finally
ComboBox3.Items.EndUpdate;
end;
end;
end.
Sve lepo funkcionise,kada se 1.put izvrsi dogadja Combo2Change,a kada se ponovo pozove taj dogadjaj u combobox3 ostaju isti podaci kao posle prethodnog pozivanja...Kako da resim problem?
HVALA !!!
Don't worry be happy