简体   繁体   English

如何在 Delphi 中编写患者搜索应用程序的代码?

[英]How to coding patient search app in Delphi?

I'm working on a patient search app.我正在开发一个病人搜索应用程序。 I have a problem with ADOQuery.Active which does not deactivate when I delete a word in the search bar.我有一个ADOQuery.Active的问题,当我在搜索栏中删除一个词时,它不会停用。

This is my code:这是我的代码:

unit Unit1;

interface

uses
  Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants, System.Classes, Vcl.Graphics,
  Vcl.Controls, Vcl.Forms, Vcl.Dialogs, Vcl.StdCtrls, Vcl.Mask, scControls,
  scDBControls, scGrids, scDBGrids, scGPControls, Data.DB, Data.Win.ADODB;

type
  TForm1 = class(TForm)
    ADOConnection1: TADOConnection;
    DataSource1: TDataSource;
    Edit1: TEdit;
    scDBGrid1: TscDBGrid;
    ADOQuery1: TADOQuery;
    ADOQuery1PATIENTId: TAutoIncField;
    ADOQuery1NAME_PAT: TStringField;
    ADOQuery1PRENOM_PAT: TStringField;
    procedure Edit1Change(Sender: TObject);

  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  Form1: TForm1;

implementation

{$R *.dfm}

procedure TForm1.Edit1Change(Sender: TObject);
begin
  if Edit1.Text = '' then
    ADOQuery1.Filtered := false
  else
  begin
    ADOQuery1.Active := true;
    ADOQuery1.Filtered := False;
    ADOQuery1.Filter := 'NAME_PAT' + ' LIKE ' + QuotedStr(Edit1.Text + '%');
    ADOQuery1.Filtered := True;
  end;
end;

end.

After clean TEdit , I set ADOQuery1.Active:= false清理TEdit后,我设置ADOQuery1.Active:= false

The problem here is you are not affecting the right properties according to your first description.根据您的第一个描述,这里的问题是您没有影响正确的属性。 Generally in database applications, you don't need to deactivate the dataset, just write an event for disabling the filter 'Filtered:= False' that will be triggered when the filter text input is cleared (by deleting the filter string manually or a "clear text" button).通常在数据库应用程序中,您不需要停用数据集,只需编写一个禁用过滤器 'Filtered:= False' 的事件,该事件将在清除过滤器文本输入时触发(通过手动删除过滤器字符串或“明文”按钮)。 But, if you need to deactivate the dataset, then you have to set that property in your code.但是,如果您需要停用数据集,则必须在代码中设置该属性。 Like this:像这样:

procedure TForm1.Edit1Change(Sender: TObject); 
begin
  if Edit1.Text = '' then 
  begin
    ADOQuery1.Filtered := False;
    ADOQuery1.Active := False;
  end
  else
  begin
    ADOQuery1.Active := True;  
    ADOQuery1.Filtered := False; 
    ADOQuery1.Filter := 'NAME_PAT' + ' LIKE ' + QuotedStr(Edit1.Text + '%');
    ADOQuery1.Filtered := True;
  end; 
end;

Here is some useful links from Delphi documentation about the "TDataSet.Active" property and how to set filters in datasets:以下是 Delphi 文档中有关“TDataSet.Active”属性以及如何在数据集中设置过滤器的一些有用链接:

https://docwiki.embarcadero.com/Libraries/Alexandria/en/Data.DB.TDataSet.Active https://docwiki.embarcadero.com/Libraries/Alexandria/en/Data.DB.TDataSet.Filter https://docwiki.embarcadero.com/RADStudio/Alexandria/en/Setting_the_Filter_Property https://docwiki.embarcadero.com/Libraries/Alexandria/en/Data.DB.TDataSet.Active https://docwiki.embarcadero.com/Libraries/Alexandria/en/Data.DB.TDataSet.Filter https:// docwiki.embarcadero.com/RADStudio/Alexandria/en/Setting_the_Filter_Property

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM