Mega Code Archive

 
Categories / Delphi / ADO Database
 

Sql edit by dark e_xplorer

//form üzerine bir Query, 4 Combobox ve DBGrid atınız //combobox1'de seçilen Alias'a göre istediğiniz SQL stringi uygulayabilirsiniz unit Unit1; interface uses Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs, StdCtrls, Grids, DBGrids, Db, DBTables, ExtCtrls, DBCtrls; type TForm1 = class(TForm) Query1: TQuery; DataSource1: TDataSource; DBGrid1: TDBGrid; Database1: TDatabase; Panel1: TPanel; ComboBox1: TComboBox; ComboBox2: TComboBox; ComboBox3: TComboBox; Table1: TTable; DBNavigator1: TDBNavigator; ComboBox4: TComboBox; procedure FormCreate(Sender: TObject); procedure ComboBox1Change(Sender: TObject); procedure ComboBox2Change(Sender: TObject); procedure ComboBox4Change(Sender: TObject); procedure ComboBox4KeyPress(Sender: TObject; var Key: Char); private { Private declarations } public { Public declarations } end; var Form1: TForm1; implementation {$R *.DFM} procedure TForm1.FormCreate(Sender: TObject); var a_list :TStringList; begin ComboBox1.Items.Clear; a_list := TStringList.Create; with Session do begin if Active then Active := FALSE; SQLHourGlass := False; if (not Active) then Active := TRUE; GetAliasNames(a_list); end; ComboBox1.Items.Assign(a_list); a_list.Free; end; procedure TForm1.ComboBox1Change(Sender: TObject); var try_open_ok :boolean; a_list :TStringList; begin if ComboBox1.Text <> '' then with Database1 do begin ComboBox2.Items.Clear; ComboBox2.Text := ''; if Connected then Close; AliasName := ComboBox1.Text; try_open_ok := True; a_list := TStringList.Create; try Session.GetTableNames(ComboBox1.Text,'',True,True,a_list); except try_open_ok := False; end; if try_open_ok then begin ComboBox2.Enabled := True; ComboBox2.Items := a_list; a_list.Free; end else begin ComboBox2.Enabled := False; end; query1.Active:=false; query1.DatabaseName:=ComboBox1.Text; end; end; procedure TForm1.ComboBox2Change(Sender: TObject); begin if ComboBox2.Text <> '' then begin ComboBox3.Items.Clear; table1.Active:=false; table1.DatabaseName:=ComboBox1.Text; table1.TableName:=ComboBox2.Text; table1.Active:=true; Table1.GetFieldNames(ComboBox3.Items); query1.Active:=false; query1.DatabaseName:=ComboBox1.Text; end; end; procedure TForm1.ComboBox4Change(Sender: TObject); begin Query1.Active:=false; end; procedure TForm1.ComboBox4KeyPress(Sender: TObject; var Key: Char); var i:integer; begin if ComboBox1.Text<>'' then begin if key=#13 then begin i := combobox4.Perform(CB_FINDSTRING,-1,LongInt(PChar(ComboBox4.text))); if i <= CB_ERR then ComboBox4.items.Add(ComboBox4.text); Query1.Active:=false; Query1.sql.Clear; Query1.sql.Add(ComboBox4.text); Query1.Active:=true; end; end; end; end.