function query(str : string);
begin
  query1.close;
  query1.sql.clear;
  query1.sql.add(str);
  query1.open;
end;
中function query(str : string);换成:procedure query(str : string);
,前者需要返回值,后者不需要。
你把自定义过程和函数定义在你的procedure ButtonClick();
下面就可以!

解决方案 »

  1.   

    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 }
      public
        { Public declarations }
      end;var
      Form1: TForm1;implementation{$R *.dfm}procedure ShowText(const AText: string);
    begin
      showmessage(AText);
    end;procedure TForm1.Button1Click(Sender: TObject);
    begin
      ShowText(DateTimeToStr(Now));
    end;end.
      

  2.   

    unit form1;
    form1=class(TForm);
     button1:TButton;
    ~~
    private
     ~~~~
    public
     procedure Button1Click(Sender:TObject);
     procedure Query(Str:string); 
    end;
    procedure Query(Str:String);
    begin  
      query1.close;
      query1.sql.clear;
      query1.sql.add(str);
      query1.open;
    end;
    procedure Button1click(Sender:TObject);
    begin
      str:='Select * from table1 ';
      query(str);
    end;procedure 没有返回值,
    function  有返回值, 
      

  3.   

    Query1是TForm的一个元素
    外界的函数是不能直接访问Query1的
    你可以把Query当成参数传递给函数