如何定义和使用一个返回boolean值得过程?

解决方案 »

  1.   

    function 函数名(参数列表):Boolean
    begin 
    result:= ;
    end;
      

  2.   

    function  ReaderCord(pBarCode: string): boolean; 
    begin
      CltDSet_Reader.Close;
      with MCltDSetFunc do
        begin
          SetValue(CltDSet_Reader,'TableName', 'tb_Reader');
          SetValue(CltDSet_Reader,'OptType', DataSelectWithTableName);
          SetValue(CltDSet_Reader,'SelectWay', SelectExact);
          SetValue(CltDSet_Reader,'SelectField', 'ReaderCord');
          SetValue(CltDSet_Reader,'ReaderCord', Trim(Edt_ReaderCord.Text));
        end;
      try
        CltDSet_Reader.Open;
        if CltDSet_Reader.RecordCount >0 then
          begin
            result := true;
            exit;
          end;
      except
        showmessage('读者控制号查重出错!');
      end;
      result := false;
    end;过程的话,就在过程内定义一个布尔值,在条件满足进就反回True,否则返回False;
      

  3.   

    要不要在前面声明?能不能写成Form5.ReaderCord().....?参数为空时,要不要价格括号()?
      

  4.   

    unit Unit1;interfaceuses
      Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
      Dialogs, StdCtrls;type
      TForm1 = class(TForm)
        Button1: TButton;
        procedure Button1Click(Sender: TObject);
      private
        { Private declarations }
        function hello():Boolean;
      public
        { Public declarations }
      end;
      function hell02():Boolean;     //看清楚位置
    var
      Form1: TForm1;implementation{$R *.dfm}function TForm1.hello: Boolean;
    begin
      Result:=true;
    end;procedure TForm1.Button1Click(Sender: TObject);
    begin
      //使用
      if hello() then
       ShowMessage('hello');
      if hello then
       ShowMessage('hello');
    end;function hell02():Boolean;
    begin
      Result:true;
    end;end.
      

  5.   

    如下规则:
    1、在使用以前声明,studentscxm(陈新明)给你的例子函数没有定义为TForm5的成员, 所以要先写了这段代码,才能其它后面实现的代码中使用;
    2、这个例子并不是TForm5的成员成员,所以不写Form5.ReaderCord(...)而直接写成ReaderCord(...);
    3、如果ReaderCord声明成TForm5的成员(Private或Public或其它段中声明),
    那么在实现时一定要写成function  TForm5.ReaderCord(pBarCode: string): boolean; 
    而这个函数的实现部分倒不必在引用它的程序代码段之前,因为已经在前面申明了的。