我的思路是用户选择preview时,弹出一个选择字段框,通过将adoquery的sql.text中的原有字段替换为所选字段.然后发出查询,用fastreport显示出来.生成的SQL语句我看是没问题,用查询分析器查也没问题,可用程序就是出错,才是出现Field:xxxx not found.请大家帮忙解决.不胜感谢.
解决方案 »
- 请问怎么样用IdUDPClient和IdUDPServer 传送大的图像和视频文件?
- 一个很郁闷的问题
- 学了delphi三个多月,有点迷惘,请大家指点!!!!散分
- 关于TChart 的问题
- 在TClientDataset.commandtext写sql语句,如果出错的,异常处理代码如和写?
- 如何在运行时去掉paradox7数据库的密码?
- 请高手帮忙解决这个IDHTTP.POST问题,如有要求人民币酬谢,谢谢。
- 有关delphi中进制转换和非10进制使用的问题,30分哦~
- Kingron(WinAPI)在你的网站上搜索 install shield 什么也没找到!
- 小虾大喊!那位高手能给于解答,用TQuery查询到的子集能否在本地进行排序而不是重发SQL命令。
- 简单问题
- 将数据集输出为文件的问题
{ Private declarations }
public
function GetGenerate(Sqlstr:String):String;
function GetCheckStr:string;
function Filterstr(Str:String):String;
{ Public declarations }
end;var
SelectFieldForms: TSelectFieldForms;implementationuses dmunit, MainAlllist;{$R *.dfm}function TSelectFieldForms.Filterstr(Str:String): String;
begin
if str='Serial Number' then
Result:='[Serial Number]'
else if str='physical-off-location' then
Result:='[physical-off-location]'
else if str='Purchase date' then
Result:='[purchase-date]'
else if str='Expiry date' then
Result:='[ma-expiry]'
else if Str='Cost' then
Result:='[ma-fee]'
else if Str='Warranty Provider' then
Result:='[provide-name]'
else if str='Category' then
Result:='[cata-name]'
else if str='Department' then
Result:='[dept-name]'
else if str='Maintenance times' then
Result:='[ma-times]'
else if str='Current Maintenance' then
Result:='Maintenance'
else if str='Memo' then
Result:='[Memo]'
else
result:=str;
end;procedure TSelectFieldForms.FormShow(Sender: TObject);
Var i:Integer;
begin
//
for i:=0 to CheckListbox1.Items.Count-1 do
CheckListBox1.Checked[i]:=true;end;function TSelectFieldForms.GetCheckStr: string;
Var i,j:integer;
Str:String;
begin
j:=0;
for i:=0 to CheckListbox1.Items.Count-1 do
begin
if CheckListBox1.Checked[i]=true then
Inc(j);
end;
if j-1=CheckListbox1.Items.Count-1 then
Result:='*'
else
begin
for i:=0 to CheckListBox1.Items.Count-1 do
begin
if CheckListBox1.Checked[i]=true then
begin
Str:=Str+FilterStr(CheckListbox1.Items.Strings[i])+','; //µÃ³ö×Ö¶Î
end;
end; Result:=str;
end;
//»¹Ã»ÓÐдÍê¡£
end;function TSelectFieldForms.GetGenerate(Sqlstr: String): String;
Var Temp1,Temp2,Temp3:string;
begin
if GetcheckStr='*' then
begin
Result:=Sqlstr;
exit;
end;
if Sqlstr<>'' then
begin
if Pos('*',Sqlstr)>0 then
begin
Temp1:=Copy(Sqlstr,0,Pos('*',Sqlstr)-1);
Temp2:=Copy(Sqlstr,(Pos('*',Sqlstr)+2),(Length(Sqlstr)-(Pos('*',Sqlstr)+2)));
Temp3:=Copy(GetCheckStr,0,Length(GetCheckStr)-1);
Result:=Temp1+' '+Temp3+' '+Temp2;
end;
end;
end;procedure TSelectFieldForms.BitBtn1Click(Sender: TObject);
Var SqlStr:string;
begin
Memo1.Clear;
// Memo1.Lines.Add(GetGenerate(dm.MainAllQuery.SQL.Text));
// ShowMessage(GetGenerate(dm.MainAllQuery.SQL.Text)); Sqlstr:=GetGenerate(dm.MainAllQuery.SQL.Text); ShowMessage(Sqlstr);
Memo1.Lines.Add(Sqlstr);
With Dm.MainAllQuery do
begin
Close;
Sql.Clear;
Sql.Add(Sqlstr);
// try
open;
// except
// raise Exception.Create('Can''t open this table');
// end;
end;
end;
{ Private declarations }
public
function GetGenerate(Sqlstr:String):String;//提取原字段,替换新字段.
function GetCheckStr:string; //检查CheckListBox中选择的字段,并转换为xx,xxx,xx,形式
function Filterstr(Str:String):String;//过滤CheckListbox中的文字为字段名
{ Public declarations }
end;var
SelectFieldForms: TSelectFieldForms;implementationuses dmunit, MainAlllist;{$R *.dfm}function TSelectFieldForms.Filterstr(Str:String): String;
begin
if str='Serial Number' then
Result:='[Serial Number]'
else if str='physical-off-location' then
Result:='[physical-off-location]'
else if str='Purchase date' then
Result:='[purchase-date]'
else if str='Expiry date' then
Result:='[ma-expiry]'
else if Str='Cost' then
Result:='[ma-fee]'
else if Str='Warranty Provider' then
Result:='[provide-name]'
else if str='Category' then
Result:='[cata-name]'
else if str='Department' then
Result:='[dept-name]'
else if str='Maintenance times' then
Result:='[ma-times]'
else if str='Current Maintenance' then
Result:='Maintenance'
else if str='Memo' then
Result:='[Memo]'
else
result:=str;
end;procedure TSelectFieldForms.FormShow(Sender: TObject);
Var i:Integer;
begin
//
for i:=0 to CheckListbox1.Items.Count-1 do
CheckListBox1.Checked[i]:=true;end;function TSelectFieldForms.GetCheckStr: string;
Var i,j:integer;
Str:String;
begin
j:=0;
for i:=0 to CheckListbox1.Items.Count-1 do
begin
if CheckListBox1.Checked[i]=true then
Inc(j);
end;
if j-1=CheckListbox1.Items.Count-1 then
Result:='*'
else
begin
for i:=0 to CheckListBox1.Items.Count-1 do
begin
if CheckListBox1.Checked[i]=true then
begin
Str:=Str+FilterStr(CheckListbox1.Items.Strings[i])+','; //µÃ³ö×Ö¶Î
end;
end; Result:=str;
end;
//»¹Ã»ÓÐдÍê¡£
end;function TSelectFieldForms.GetGenerate(Sqlstr: String): String;
Var Temp1,Temp2,Temp3:string;
begin
if GetcheckStr='*' then
begin
Result:=Sqlstr;
exit;
end;
if Sqlstr<>'' then
begin
if Pos('*',Sqlstr)>0 then
begin
Temp1:=Copy(Sqlstr,0,Pos('*',Sqlstr)-1);
Temp2:=Copy(Sqlstr,(Pos('*',Sqlstr)+2),(Length(Sqlstr)-(Pos('*',Sqlstr)+2)));
Temp3:=Copy(GetCheckStr,0,Length(GetCheckStr)-1);
Result:=Temp1+' '+Temp3+' '+Temp2;
end;
end;
end;procedure TSelectFieldForms.BitBtn1Click(Sender: TObject);
Var SqlStr:string;
begin
Memo1.Clear;
// Memo1.Lines.Add(GetGenerate(dm.MainAllQuery.SQL.Text));
// ShowMessage(GetGenerate(dm.MainAllQuery.SQL.Text)); Sqlstr:=GetGenerate(dm.MainAllQuery.SQL.Text); ShowMessage(Sqlstr);
Memo1.Lines.Add(Sqlstr);
With Dm.MainAllQuery do
begin
Close;
Sql.Clear;
Sql.Add(Sqlstr);
// try
open;
// except
// raise Exception.Create('Can''t open this table');
// end;
end;
end;
1.
//在此處是否需要加一個初始化的動作?不過不加好象也沒有事,
//因為局部變量會自動初始化的
for i:=0 to CheckListBox1.Items.Count-1 do
begin
if CheckListBox1.Checked[i]=true then
begin
Str:=Str+FilterStr(CheckListbox1.Items.Strings[i])+',';
//此處返回時,是不是多了一個","號?
end;
end; Result:=str;
2.在Filterstr過程中,你用的是字符串比較
所以要注意大小寫的問題