我在Delphi 6中创建了一个Application.其中只有一个Unit1单元文件
Unit 1代码如下:
unit Unit1;interfaceuses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, StdCtrls;type
  TForm1 = class(TForm)
    Edit1: TEdit;
    Button1: TButton;
    procedure Button1Click(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;  TStaff=class
privatepublic
  name:string;
end;var
  Form1: TForm1;
  Staff: TStaff;
implementation
{$R *.dfm}
procedure TForm1.Button1Click(Sender: TObject);
begin
   staff.name:=edit1.Text;end;end.
   但每次运行它并click  button1时,delphi总会提示出错:access violation at address 0404428 in moudle ,project1 wirte of address 000000004........
为什么啊??
   

解决方案 »

  1.   


    staff := TStaff.Create; 
    staff.name:=edit1.Text;
      

  2.   

    Staff=class(Tobject)
    有人说可能是因为我的机子里的病毒所致,我想不大可能吧?
      

  3.   

    procedure TForm1.Button1Click(Sender: TObject);
    begin
      staff = TStaff.create(self);
       staff.name:=edit1.Text;end;应该可以,还有就是最好不要把staff在那里定义,很容易出错,我也是刚刚知道。
      

  4.   

    http://expert.csdn.net/Expert/topic/1390/1390243.xml?temp=.178692看看这个,是不是有些帮助?
      

  5.   

    这不用试,当然可以!就加这一句:Staff:=TStaff.Create;其它什么都不用,如果从TObject继承,可以省略TObject!
      

  6.   

    to  idilent(说错了别怪我) 
    staff = TStaff.create(self);????---create 后那有参数的啊!我用的是delphi 6
      

  7.   

    妈的,我的机子就是不行啊!是不是IDE中有什么参数设置错了!
      

  8.   

    当然没有参数constructor Create(AOwner: TComponent); virtual;参数是类TComponent虚构Create时产生的,自己从TObject继承哪来的参数!按照我和darkeye写的不就可以了吗?还是拿本书来学点基础吧!
      

  9.   

    给分!
    TStaff=class
    private
    fName:String;
    public
       property Name: string read fName write fName;
    end;
      

  10.   

    在使用之前来一句staff:=Tstaff.create;实例化