编写一查询程序,利用函数对Edit类型窗口的输入进行验证,(判断是否为数字型/(非法字符,空格)等。)代码如下:unit Unit4;interfaceuses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, StdCtrls, ComCtrls, Grids, DBGrids, DB, ADODB, DBTables;type
  Tsarch = class(TForm)
    HeaderControl1: THeaderControl;
    GroupBox1: TGroupBox;
    Label1: TLabel;
    Label2: TLabel;
    Edit2: TEdit;
    ComboBox1: TComboBox;
    Label3: TLabel;
    Label4: TLabel;
    ComboBox2: TComboBox;
    Button1: TButton;
    Button2: TButton;
    GroupBox2: TGroupBox;
    GroupBox3: TGroupBox;
    DataSource1: TDataSource;
    DBGrid1: TDBGrid;
    GroupBox4: TGroupBox;
    Button3: TButton;
    Button4: TButton;
    Button5: TButton;
    Button6: TButton;
    GroupBox5: TGroupBox;
    Button7: TButton;
    Button8: TButton;
    Edit1: TEdit;
    Query1: TQuery;
    hsj: TDatabase;
    procedure FormClose(Sender: TObject; var Action: TCloseAction);
    procedure Button3Click(Sender: TObject);
    procedure Button6Click(Sender: TObject);
    procedure Button4Click(Sender: TObject);
    procedure Button5Click(Sender: TObject);
    procedure Button1Click(Sender: TObject);
    procedure Button2Click(Sender: TObject);
    procedure Button7Click(Sender: TObject);
  private
    { Private declarations }    s:string;
    function isInteger(s:string):boolean;  ----》》》》》此处报错
  public
    { Public declarations }
  end;var
  sarch: Tsarch;implementation{$R *.dfm}procedure Tsarch.FormClose(Sender: TObject; var Action: TCloseAction);
begin
begin
action:=cafree;
sarch:=nil;
end;
end;procedure Tsarch.Button3Click(Sender: TObject);
begin
query1.first;
end;procedure Tsarch.Button6Click(Sender: TObject);
begin
query1.last;
end;
procedure Tsarch.Button4Click(Sender: TObject);
begin
query1.prior;
end;procedure Tsarch.Button5Click(Sender: TObject);
begin
query1.next;
end;
procedure Tsarch.Button1Click(Sender: TObject);var
   i:integer;
  // s:string;begin
   s:='select  id as 员工编号 , name as 姓名 , sex as 性别,  birthday as 出生日期, education as 学历,department as 部门 , headship as 职务  from Employee ';
   i:=0;
   {处理员工编号}
   if isInteger(edit1.text)then   begin
      s:=s+'where id='+edit1.Text;
      i:=i+1;
   end;
   {处理员工姓名}
   if edit2.Text<>'' then
   begin      if i=0 then
         s:=s+'where name='''+edit2.Text+''''
      else
         s:=s+' and  name='''+edit2.Text+'''';
      i:=i+1;
   end;
   if i=0 then
      s:=s+'where '
   else    with query1 do
    begin
      close;
      sql.Clear;
      sql.Add(s);
      try
         open;
      except
         execsql;
      end;
    end;
end;procedure Tsarch.Button2Click(Sender: TObject); //函数部分
begin
Edit1.Text:='';
Edit2.Text:='';
end;procedure Tsarch.Button7Click(Sender: TObject);
begin
//frmChangeMember:=TFrmChangeMember.create(self);
//frmChangeMember.showModal;end;end.
function Tsarch.isInteger(s: string): boolean;--------》报错
var
   i:integer;
begin
   i:=1;
   if length(s)=0 then
   begin
      result:=false;
      exit;
   end;
   while i<=length(s) do
   begin
      if (isNumeric(s[i])=false) then
      begin
         result:=false;
         exit;
      end;
      i:=i+1;
   end;
   result:=true;
end;end.头都看晕,一直不知起解,谢谢各为解答,谢谢~~~

解决方案 »

  1.   

    我把你的函数copy过来,改了一个if (isNumeric(s[i])=false) then,好像没错啊,
    是不是isNumeric你写错了啊?
    code:function isInteger(s: string): boolean;//--------》报错
    var
       i:integer;
    begin
       i:=1;
       if length(s)=0 then
       begin
          result:=false;
          exit;
       end;
       while i<=length(s) do
       begin
          //if (isNumeric(s[i])=false) then
          if not (s[i] in ['0'..'9']) then
          begin
             result:=false;
             exit;
          end;
          i:=i+1;
       end;
       result:=true;
    end;procedure TForm1.Button1Click(Sender: TObject);
    begin
       if isInteger('564') then
         showmessage('true')
       else
         showmessage('False');
    end;
      

  2.   

    刚才没注意看isNumeric是系统函数,我把屏蔽的改过来没问题啊?
    你是不是没有加载啊 IdGlobal单元啊?好像也可能会这么大意哦
      

  3.   

    谢谢:wuyu1981(方圆)。不好意思,我还是不明白。这里不用加载IDglbal 单元。
    刚刚写错了,函数在这里:function Tsarch.isInteger(s: string): boolean;
    var
       i:integer;
    begin
       i:=1;
       if length(s)=0 then
       begin
          result:=false;
          exit;
       end;
       while i<=length(s) do
       begin
          if (isNumeric(s[i])=false) then
          begin
             result:=false;
             exit;
          end;
          i:=i+1;
       end;
       result:=true;
    end;end.
      

  4.   

    自定义函数未声明,在interface的type部分声明
    function isInteger(s: string): boolean;
      

  5.   

    private
        { Private declarations }
        s:string;
        function isInteger(s:string):boolean;
    ...
    .
    ..
    ..
    声明了啊。
      

  6.   

    [Warning] Unit4.pas(161): Text after final 'END.' - ignored by compiler
    [Error] Unit4.pas(49): Unsatisfied forward or external declaration: 'Tsarch.isInteger'
    [Fatal Error] Project1.dpr(9): Could not compile used unit 'Unit4.pas'
      

  7.   

    procedure Tsarch.Button7Click(Sender: TObject);
    begin
    //frmChangeMember:=TFrmChangeMember.create(self);
    //frmChangeMember.showModal;end;end.------------>这里错了!
      

  8.   

    tks。
    可是还是有错。
    function Tsarch.isInteger(s: string): boolean;
    var
       i:integer;
    begin
       i:=1;
       if length(s)=0 then
       begin
          result:=false;
          exit;
       end;
       while i<=length(s) do
       begin
          if (isNumeric(s[i])=false) then--------》报错
          begin
             result:=false;
             exit;
          end;
          i:=i+1;
       end;
       result:=true;
    end;end.[Error] Unit4.pas(173): Undeclared identifier: 'isNumeric'
      

  9.   

    “加入IdGlobal单元就可以了!”接触delphi不久。不知道其解。实在不好意思,还请赐教
      

  10.   

    晕啊,你的分还真不好接,不过这次就好人做到底了!
    uses
      Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
      Dialogs, StdCtrls, ComCtrls, Grids, DBGrids, DB, ADODB, DBTables, IdGlobal;//最后这个就是