出错,access异常?????访问year,即test.GetYear 异常!!!!
为什么???unit Unit2;interfacetype
    TTest = Class
    private
     year,mon,day:integer;
    public
    constructor Create;overload;
    public    function  GetYear():integer;
    end;var
test:TTest;implementation{ TTest }constructor TTest.Create;
begin
   year:=1;
   mon:=2;
   day:=3;
end;function TTest.GetYear: integer;
begin
     Result:=year;
end;end.
////////////////////////////////////////////////////////
unit Unit1;interfaceuses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs;type
  TForm1 = class(TForm)
    procedure FormCreate(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;var
  Form1: TForm1;implementationuses Unit2;
{$R *.dfm}procedure TForm1.FormCreate(Sender: TObject);
begin
  test:=test.Create;
 showmessage(IntToStr(test.GetYear))
end;
end.

解决方案 »

  1.   

    test:=test.Create改为
    test:=Ttest.Create
      

  2.   

    unit Unit2;interfacetype
        TTest = Class
        private
          Fyear,Fmon,Fday: integer;
        public
          constructor Create;overload;
          function  GetYear:integer;
          function  SetYear(Value: Integer):integer;
          property year: integer Read GetYear write SetYear;
        end;
    function  SetYear(Value: Integer):integer;
    begin
      if Value <> FYear then Fyear := Value;
    end;  //在另一個單元引用,需是Public or Publish