function ADDListView:Boolean;  //定义房台列表显示函数
var
list1:tlistitem;
begin
   frm_front.ListView1.Clear;
   frm_front.adotable2.Refresh;
   while not frm_front.adotable2.eof do
      begin
        if frm_front.ADOTable2.FieldByName('eating').AsBoolean then
           begin
           list1:=frm_front.ListView1.Items.Add;
           list1.ImageIndex:=0;
           list1.Caption:=frm_front.adotable2.fieldbyname('id').asstring;
           end
           else
             if frm_front.ADOTable2.FieldByName('revert').AsBoolean then
                 begin
                 list1:=frm_front.ListView1.Items.Add;
                 list1.ImageIndex:=1;
                 list1.Caption:=frm_front.adotable2.fieldbyname('id').asstring;
                 end
                 else
                    begin
                    list1:=frm_front.ListView1.Items.Add;
                    list1.ImageIndex:=2;
                    list1.Caption:=frm_front.adotable2.fieldbyname('id').asstring;
                    end;
      frm_front.adotable2.next;
      end;
end;

解决方案 »

  1.   

    在interface里声明这个函数不就好了
      

  2.   

    unit unit1;interface
    uses  Forms, Windows, Messages;//用到什么就引用什么function ADDListView:Boolean;  //定义房台列表显示函数 //这里就是声明implementation
    //这里是实现。
    function ADDListView:Boolean;  //定义房台列表显示函数
    var
    list1:tlistitem;
    begin
       frm_front.ListView1.Clear;
       frm_front.adotable2.Refresh;
       while not frm_front.adotable2.eof do
          begin
            if frm_front.ADOTable2.FieldByName('eating').AsBoolean then
               begin
               list1:=frm_front.ListView1.Items.Add;
               list1.ImageIndex:=0;
               list1.Caption:=frm_front.adotable2.fieldbyname('id').asstring;
               end
               else
                 if frm_front.ADOTable2.FieldByName('revert').AsBoolean then
                     begin
                     list1:=frm_front.ListView1.Items.Add;
                     list1.ImageIndex:=1;
                     list1.Caption:=frm_front.adotable2.fieldbyname('id').asstring;
                     end
                     else
                        begin
                        list1:=frm_front.ListView1.Items.Add;
                        list1.ImageIndex:=2;
                        list1.Caption:=frm_front.adotable2.fieldbyname('id').asstring;
                        end;
          frm_front.adotable2.next;
          end;
    end;
    end.你只要在其他的单元中uses unit1,就可以使用这个函数了。明白?
      

  3.   

    我也知道是在哪里定义,但我不知道这个函数定义的语法,如果就是
    function ADDListView:Boolean;总是提示语法出错
      

  4.   

    直接复制到uses子句下不就完了,虽然那样不是很正规。
      

  5.   

    unit p_front;interfaceuses
      Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
      Dialogs, StdCtrls, DBCtrls, ComCtrls, Buttons, ExtCtrls,p_datam, DB,
      Grids, DBGrids, ADODB, ImgList;type
      Tfrm_front = class(TForm)
        Panel1: TPanel;
        Panel2: TPanel;
        BitBtn1: TBitBtn;
        BitBtn2: TBitBtn;
        BitBtn3: TBitBtn;
        BitBtn4: TBitBtn;
        BitBtn5: TBitBtn;
        BitBtn6: TBitBtn;
        DBText1: TDBText;
        DataSource1: TDataSource;
        ADOTable1: TADOTable;
        ADOTable2: TADOTable;
        DataSource2: TDataSource;
        procedure FormShow(Sender: TObject);
        procedure ListView1Click(Sender: TObject); 
        procedure FormClose(Sender: TObject; var Action: TCloseAction);
        procedure FormCreate(Sender: TObject);
        function ADDListView:Boolean;//这样定义这个函数时就提示出错?应如何定义??????? 
    private
        { Private declarations }
      public
        s,roomn,tablen:string;
       { Public declarations }
      end;var
      frm_front: Tfrm_front;
      list1,list2:TlistItem;
      i:integer=0;
      //tablen:string;
    implementationuses p_order_h, p_cash;{$R *.dfm}function ADDListView:Boolean;  //定义房台列表显示函数
    var
    list1:tlistitem;
    begin
       frm_front.ListView1.Clear;
       frm_front.adotable2.Refresh;
       while not frm_front.adotable2.eof do
          begin
            if frm_front.ADOTable2.FieldByName('eating').AsBoolean then
               begin
               list1:=frm_front.ListView1.Items.Add;
               list1.ImageIndex:=0;
               list1.Caption:=frm_front.adotable2.fieldbyname('id').asstring;
               end
               else
                 if frm_front.ADOTable2.FieldByName('revert').AsBoolean then
                     begin
                     list1:=frm_front.ListView1.Items.Add;
                     list1.ImageIndex:=1;
                     list1.Caption:=frm_front.adotable2.fieldbyname('id').asstring;
                     end
                     else
                        begin
                        list1:=frm_front.ListView1.Items.Add;
                        list1.ImageIndex:=2;
                        list1.Caption:=frm_front.adotable2.fieldbyname('id').asstring;
                        end;
          frm_front.adotable2.next;
          end;
    end;
      

  6.   

    function ADDListView:Boolean;//这样定义这个函数时就提示出错?应如何定义??????? 
    {这样定义没有错。}
    ----------------------------
    function ADDListView:Boolean;  //定义房台列表显示函数
    {你的函数定义在Tfrm_front类中,必需声明为类成员函数,改为:
    function Tfrm_front.ADDListView:Boolean;  //定义房台列表显示函数}
    var
    list1:tlistitem;
    begin
       frm_front.ListView1.Clear;
       frm_front.adotable2.Refresh;
       ...
    end;