DELPHI盒子
!实时搜索: 盒子论坛 | 注册用户 | 修改信息 | 退出
检举帖 | 全文检索 | 关闭广告 | 捐赠
技术论坛
 用户名
 密  码
自动登陆(30天有效)
忘了密码
≡技术区≡
DELPHI技术
lazarus/fpc/Free Pascal
移动应用开发
Web应用开发
数据库专区
报表专区
网络通讯
开源项目
论坛精华贴
≡发布区≡
发布代码
发布控件
文档资料
经典工具
≡事务区≡
网站意见
盒子之家
招聘应聘
信息交换
论坛信息
最新加入: deliping
今日帖子: 2
在线用户: 1
导航: 论坛 -> DELPHI技术 斑竹:liumazi,sephil  
作者:
男 zyhkernel (蓝色闪电) ★☆☆☆☆ -
普通会员
2004/3/24 17:10:06
标题:
使用另一个文件中定义的类出错_小弟毕业设计急需解决的问题sos 浏览:1343
加入我的收藏
楼主: 请各位大虾帮忙看看:在一个类中使用他单元定义的一个类.

这是我在UwordAnalyze.pas中定义的一个类:
unit UwordAnalyze;
interface
uses
    Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, Menus, StdCtrls,UwordList,Math;

type
     TWordAnalyze=class
     private
       {private declarations}
       sourceFile:File of char;  //变量成员定义
       testFile:File of string[8];
       ……
       procedure readCh(var ch:char);   //方法定义
       procedure noBlank(var ch:char);
       ……
     public
        {public declarations}
        fileDir:string;
        function  connect(fileDir:string):Boolean;          
        procedure scanner(); 
        ……
end;

implementation        //以下是对各种方法的实现

procedure readCh(var ch:char);
begin
     ……
end;

……
……

end.
------------------------------------------------------------------------
后来我在程序中使用以上定义的这个类
unit Umain;   //Umain.pas
interface
uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, Menus, StdCtrls,UwordList,Math,UwordAnalyze; //引用了上面的那个单元

type
  TMainForm = class(TForm)
    OpenDialog1: TOpenDialog;
    Label1: TLabel;
    Button1: TButton;
    Button2: TButton;
    wordAnalyze:TWordAnalyze;    //再这里引用了以上定义的那个类
    procedure OpenClick(Sender: TObject);
    procedure Button1Click(Sender: TObject);
    procedure Button2Click(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  MainForm: TMainForm;

implementation

{$R *.dfm}

……
……
procedure TMainForm.Button2Click(Sender: TObject); //在这里用到了这个类,并将其实例化
begin
      if OpenDialog1.Execute then
      begin
            wordAnalyze:=TWordAnalyze.Create;
            wordAnalyze.fileDir:=OpenDialog1.FileName;
            if wordAnalyze.connect(wordAnalyze.fileDir) then
               wordAnalyze.scanner;
      end;
end;

end.

编译时提示错误:Field MainForm.wordAnalyze does not have a corresponding component. Remove the declaration?
我觉得这可能是在类定义和使用中缺了什么东西,可是我翻遍全书还是找不到答案(因为书中的例子都是在本单元内对定义的类进行实例化的)。实在没有办法才来麻烦大家给看一看问题究竟处在哪儿?
请各位高手不吝赐教,这个问题对我很重要。谢谢!
----------------------------------------------
学习中……
作者:
男 bios (阿贡) ★☆☆☆☆ -
盒子中级会员
2004/3/24 20:39:38
1楼: 不是缺东西 是放的位置不对
DELPHI默认是publish是对设计时控件而言的

和其他面向对象语言不同所以
吧那个类对象 变量 放到 public段就OK!
----------------------------------------------
按此在新窗口浏览图片
按此在新窗口浏览图片
信息
登陆以后才能回复
Copyright © 2CCC.Com 盒子论坛 v3.0.1 版权所有 页面执行68.35938毫秒 RSS