Delphi中如何实现查询功能:如下介绍

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Delphi中如何实现查询功能:如下介绍相关的知识,希望对你有一定的参考价值。

用到ComboBox 其Items 有如图三条lines ;用的是SQL 数据库
procedure TF_demo.Button3Click(Sender: TObject); //模糊查询
begin
adotable1.close;
datasource1.DataSet:=adoquery1;
if trim(Edit1.Text)<>'' then
begin
adoquery1.close;
adoquery1.sql.clear;
adoquery1.SQL.Add('select * from people ');//添加条件
adoquery1.sql.add(' where name like '''+'%'+Edit1.text+'%'+'''');
adoquery1.open;
end; 这是我只查询姓名的代码 没有错 。现在想实现 如图的查询功能 ,选择不同的lines 输入相应内容 就可以按lines条件查询,并且 查询按钮会捕捉相应的lines给予提示,希望高手给出代码 和相关设置属性。

参考技术A 看看你是不是这个意思 ?
procedure TF_demo.Button3Click(Sender: TObject); //模糊查询
begin
adotable1.close;
datasource1.DataSet:=adoquery1;
if trim(Edit1.Text)<>'' then
begin
adoquery1.close;
adoquery1.sql.clear;
adoquery1.SQL.Add('select * from people ');//添加条件
if trim(combobx1.text) = '按班级查询' then //防止输入items属性时,输入空格,可以加trim()命令,下面相同,需要可以自己加。
adoquery1.sql.add(' where 班级字段 like '''+'%'+Edit1.text+'%'+'''');
if combobx1.text = '按专业查询' then
adoquery1.sql.add(' where 专业字段 like '''+'%'+Edit1.text+'%'+'''');
if combobx1.text = '按姓名查询' then
adoquery1.sql.add(' where name like '''+'%'+Edit1.text+'%'+'''');
adoquery1.open;
end;
其它就是找到combobox1的items属性,双击
然后输入
按班级查询
按专业查询
按姓名查询本回答被提问者采纳
参考技术B 首先定义一个变量strColumn,
然后再进行判断
if trim(combobx1.text) = '按班级查询' then
strcolumn=‘class’
if combobx1.text = '按专业查询' then
strcolumn=‘major’
if combobx1.text = '按姓名查询' then
strcolumn='name'
最后,在查询语句中,
adoquery1.sql.add(' where '+strcolumn+' like '''+'%'+Edit1.text+'%'+'''');
搞定。。
参考技术C Delphi基本没用过,不过你左面可以用下拉列表,查询时根据列表的数值(具体查Delphi的控件帮助),只改变这一句adoquery1.sql.add(' where name like '''+'%'+Edit1.text+'%'+'''');
对应不同的sql列名,其他的不用变化
具体代码还要等高人,我算是帮顶,呵呵

Delphi如何实现选中文件或文件夹

13-954 加油!~ 呵呵,很久没见你有动静了!////////////////////楼主的意思其实是像迅雷下载完文件后,在"已下载"列表里对某个已下载的文件执行 右键->打开文件夹 一样的效果,也即直接打开文件所在的目录,并使文件呈蓝色的选定状态,很多软件都能实现这种功能,但相关资料貌似并不多,下边来我来说说这招武林上不外传的玄冥神掌(自吹自擂),揭开它的神效,其实我所知道的有两种方法能实现,先说第一种最简单的,就是用资源管理器命令开关,如下代码:uses Shellapi; //以便使用ShellExecute function OpenAndSetFileSelected(const aFullExename: String): Boolean;
begin
Result:= FileExists(aFullExename);
if Result then
ShellExecute(0, \'open\', \'explorer.exe \', PChar(\'/select, \'+aFullExename),nil,SW_NORMAL);
end;procedure TForm1.Button1Click(Sender: TObject);
begin
OpenAndSetFileSelected(\'C:\\WINDOWS\\regedit.exe\');
end;/////////////////////////////////可以在开始菜单->运行 里试试下边的命令,效果一样的explorer /select,c:\\windows\\regedit.exe顺便,把其它的开关也一并列出来吧更多信息syntaxEXPLORER.EXE [ /n ] [ /e ] [,/ root,<object> ] [ [,/ select ],< sub object...syntax
EXPLORER.EXE [ /n ] [ /e ] [,/ root,<object> ] [ [,/ select ],< sub object > ]
explorer 命令开关
/n: Opens a new window in single-paned (My Computer) view for each item
selected, even if the new window duplicates a window that is
already open./e: Uses Windows Explorer view. Windows Explorer view is most similar
to File Manager in Windows version 3.x. Note that the default view
is Open view./root,<object>: Specifies the root level of the specified view. The
default is to use the normal namespace root (the
desktop). Whatever is specified is the root for the
display./select,<sub object>: Specifies the folder to receive the initial
focus. If "/select" is used, the parent folder
is opened and the specified object is selected.
若要 to open Windows Explorer view to only objects explore on \\\\<server name >,use following syntax:
Explorer/e,/ 根,\\\\ < 服务器名 >
若要查看在 C:\\WINDOWS\\System32 文件夹并选择 CALC.EXE,使用以下语法:
explorer /select,c:\\windows\\system32\\calc.exe
例子:(可以将下边的命令复制到"运行"里回车试试)打开 c:\\windows 目录并选定 explorer.exe 文件
explorer.exe /select,"c:\\windows\\explorer.exe"
explorer.exe /n,/select,"c:\\windows\\explorer.exe" 加上 /n, 表示不管当前是否有已打开的c:\\windows目录,都会打开一个新的窗口explorer.exe /n,/e,/select,"c:\\windows\\explorer.exe" 加上 /e, 表示展开左边的目录树
参考技术A 选中文件夹,这个难度有点大的。如果是选中文件可以用OpenDialog1控件的。

以上是关于Delphi中如何实现查询功能:如下介绍的主要内容,如果未能解决你的问题,请参考以下文章

delphi cxgrid控件中自定义筛选,用like时,要加% %才能实现模糊查询,如何不要输入% %就能实现。

DELPHI中如何使用ADOQUERY和TEDIT,TMEMO操作数据库。

Delphi的DLL里如何实现定时器功能?

Delphi如何实现选中文件或文件夹

在delphi中如何实现cxGrid控件一个单元格显示多个操作按钮

delphi中如何实现checkbox的多选