您的位置:首页 > 编程语言 > Delphi

Delphi - 关于错误E2002 File Type is not allowed here

2012-02-01 00:39 676 查看
======================================================

注:本文源代码点此下载

======================================================

技术交流,dh讲解.
最近写的程序里面想加入一个log的功能,为了方便以后使用,所以就打算写一个控件.结果遇到了一个问题,这里和大家分享.procedure dosetfile(atxt: textfile; const filename: string);
begin
assignfile(atxt, filename);
if fileexists(filename) then
append(atxt)
else
rewrite(atxt);
end;
我是这样声明的,理论来说不应该有问题,结果delphi就报了这个错误,文件类型不允许使用在这里.这个问题第一次遇到了,把函数声明改到控件里面也是这个错误.没有办法了 只有google一下.
看见一个老外也问了这个问题.
在一堆e文中 找呀找呀,终于看到一个人回答.给了我个提示.好吧我们改函数.
procedure dosetfile(var atxt: textfile; const filename: string);
begin
assignfile(atxt, filename);
if fileexists(filename) then
append(atxt)
else
rewrite(atxt);
end;
只是增加了一个var 结果就可以了.
因为我们这里可能改了atxt,但是如果直接传值参肯定不行了,所以delphi给了我们错误提示.
希望能对大家有帮助.
附上e文:有能力的朋友自己看下:
file types are not allowed as value parameters and as the base type of a file type itself. they are also not allowed as function return types, and you cannot assign them - those errors will
however produce a different error message.
program produce;
procedure writeinteger(t: text; i: integer);
begin
writeln(t, i);
end;
begin
end.
in this example, the problem is that t is value parameter of type text, which is a file type. recall that whatever gets written to a value parameter has no effect on the caller's copy of
the variable - declaring a file as a value parameter therefore makes little sense.
program solve;
procedure writeinteger(var t: text; i: integer);
begin
writeln(t, i);
end;
begin
end.
declaring the parameter as a var parameter solves the problem.
retrieved from "http://docwiki.embarcadero.com/radstudio/en/e2002_file_type_not_allowed_here_(delphi)"
好结束,我是dh.
绿色通道:好文要顶关注我收藏该文与我联系



======================================================

在最后,我邀请大家参加新浪APP,就是新浪免费送大家的一个空间,支持PHP+MySql,免费二级域名,免费域名绑定
这个是我邀请的地址,您通过这个链接注册即为我的好友,并获赠云豆500个,价值5元哦!短网址是http://t.cn/SXOiLh我创建的小站每天访客已经达到2000+了,每天挂广告赚50+元哦,呵呵,饭钱不愁了,\(^o^)/
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: 
相关文章推荐