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


======================================================
注:本文源代码点此下载
======================================================

技术交流,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^)/
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值