首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > .NET > .NET >

过程类型声名有关问题

2012-02-03 
过程类型声名问题以下程序发生:project1.exeraisedexceptionclassEAccessViolationwithmessageAccessviola

过程类型声名问题
以下程序发生:project1.exe   raised   exception   class   EAccessViolation   with   message   'Access   violation   at   address   00000000.   Read   of   address00000000 '.   Process   stopped.   Use   Step   or   Run   to   continue.错误信息。请问以下代码错在哪里?执行Myfun(12)执行的是什么运算?     f()函数会兼容定义的过程类型嘛?


  public
        {   Public   declarations   }

    end;
    TMyFun=function(i:integer):integer;{声名一个过程类型}
var
    Form1:   TForm1;
    Myfun:TmyFun;

implementation

{$R   *.dfm}

function   f(i:integer):Integer;
begin
    result:=i*2;
end;
function   f2(j:integer):integer;
begin
    result:=j+100;
end;
procedure   TForm1.Button1Click(Sender:   TObject);

begin
    Edit1.Text:=inttostr(myfun(12));
end;

end.



[解决办法]
TMyFun没有实现吧
[解决办法]
procedure TForm1.Button1Click(Sender: TObject);
begin
MyFun := f2; // 加上这句 or := f;
Edit1.Text:=inttostr(myfun(12));
end;
[解决办法]
写法有问题 
var 
myfun: TMyFun;
....
myFun := f; //myfun := f2;
Edit1.Text:=inttostr(myfun(12)); 

[解决办法]
你只是声明了MyFun这个变量并没有对其赋值呀,直接引用当然会出错啦。
[解决办法]
你这个错误类似于这段代码的错误
var bt:TStrings;
begin
//必须有下面的构造函数才行,不然会出现异常
//bt:=TStringList.Create;
bt.Add(' ');
end;

热点排行