各位DFW帮忙看看,楼主的问题解决方法,有没有需要修改的地方?
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, DB, StdCtrls, ADODB, Grids, DBGrids;
type
TForm1 = class(TForm)
DBGridView: TDBGrid;
ADOConnection1: TADOConnection;
ADOQueryView: TADOQuery;
ADOQueryEditFields: TADOQuery;
listShowFields: TListBox;
ButShowView: TButton;
DataSource1: TDataSource;
listGetfields: TListBox;
ButUp: TButton;
ButDown: TButton;
procedure FormShow(Sender: TObject);
procedure listGetfieldsDblClick(Sender: TObject);
procedure listShowFieldsDblClick(Sender: TObject);
procedure ButUpClick(Sender: TObject);
procedure ButDownClick(Sender: TObject);
procedure ButShowViewClick(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
procedure TForm1.FormShow(Sender: TObject);
var
I :integer;
StrfieldName:string;
StrSQLGetAllFields:string;
begin
strsqlgetallfields:='select * from s_score_sen1'; //S_Score_sen1 为表名(因为楼主没给我数据库结构,所以用自己的表来代替) 修改连接
with self.ADOQueryEditFields do //修改时把表的名字改一下,以下相同
begin
close;
sql.Clear ;
sql.Add(Strsqlgetallfields);
open;
for i:=0 to self.ADOQueryEditFields.FieldCount -1 do
begin
strfieldname:=Trim(fields.Fields.FieldName);
self.listgetFields.Items.Add(strfieldname);
end;
end;
end;
procedure TForm1.listGetfieldsDblClick(Sender: TObject);
begin
if self.listGetfields.ItemIndex >=0 then
begin
Listshowfields.Items.Add(Listgetfields.Items.Strings[Listgetfields.ItemIndex]);
Listgetfields.DeleteSelected;
end;
end;
procedure TForm1.listShowFieldsDblClick(Sender: TObject);
begin
if self.listshowfields.ItemIndex >=0 then
begin
Listgetfields.Items.Add(Listshowfields.Items.Strings[Listshowfields.ItemIndex]);
Listshowfields.DeleteSelected;
end;
end;
procedure TForm1.ButUpClick(Sender: TObject);
begin
self.ButDown.Enabled :=true;
if self.listShowFields.ItemIndex >=0 then
with self.listShowFields do
begin
if itemindex>0 then
begin
self.ButUp.Enabled :=true;
Items.Exchange(ItemIndex,ItemIndex-1) ;
end
else
self.ButUp.Enabled :=false;
end;
end;
procedure TForm1.ButDownClick(Sender: TObject);
begin
self.ButUp.Enabled :=true;
if self.listShowFields.ItemIndex >=0 then
with self.listShowFields do
begin
if itemindex<items.Count-1 then
begin
self.Butdown.Enabled :=true;
Items.Exchange(ItemIndex,ItemIndex+1) ;
end
else
self.Butdown.Enabled :=false;
end;
end;
procedure TForm1.ButShowViewClick(Sender: TObject);
var
StrSqlShowView:String;
i:integer;
begin
StrSQLshowview:='select ';
for i:=0 to self.listShowFields.Items.Count-2 do
begin
strsqlshowview :=Strsqlshowview+ trim(self.listShowFields.Items.Strings)+',';
end;
Strsqlshowview:=strsqlshowview+ trim(self.listShowFields.Items.Strings[self.listShowFields.Items.count-1])+' ';
strsqlshowview:=strsqlshowview+'from S_Score_Sen1';
with self.ADOQueryView do
begin
close;
sql.Clear ;
sql.Add(Strsqlshowview);
open;
end;
end;
end.