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^)/
注:本文源代码点此下载
======================================================
技术交流,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^)/
相关文章推荐
- Delphi - 关于错误E2002 File Type is not allowed here
- Delphi - 关于错误E2154 Type '%s' needs finalization - not allowed in variant record
- Delphi - 关于错误E2154 Type '%s' needs finalization - not allowed in variant record
- 关于写入文件缓存时报"java.io.FileNotFoundException open failed (is a director)"错误的解决方法
- Delphi - 关于错误E1038 Unit identifier '%s' does not match file name
- 关于Jquery错误的解决:Uncaught TypeError: $.post is not a function
- pointer to incomplete class type is not allowed 错误
- FCKeditor关于图片上传出现错误“ 提示没有权限 Type=Image” 以及出现"this connector is disabled Please check the"editor/filemanager/connectors/aspx/conf
- response错误:Request header field Content-Type is not allowed by Access-Control-Allow-Headers in prefl
- 关于Eclipse导入的Maven项目报:" cannot be read or is not a valid ZIP file"错误的解决方案
- 关于调用listFile()在遍历含有乱码文件时出现input is not valid Modified UTF-8错误的解决方法
- TypeError: a.replace is not a function 错误
- intellij idea 中 maven-war-plugin element encoding is not allowed here
- 关于jquery使用live()方法的问题Uncaught TypeError: $(...).live is not a function
- 怎么解决mysql不允许远程连接的错误1130 - Host'xxx.xxx.xxx.xxx' is not allowed to connect to this MySQL server“
- 错误中学习--TypeError: Ext.panel is not a constructor
- 关于错误 The type or namespace name `Vuforia' could not be found. Are you missing an assembly reference?
- 错误:#{...} is not allowed in template text
- Eclipse 编译错误 Access restriction:The type *** is not accessible due to restriction on... 解决方案
- 关于xml配置文件无元素提示和the root element of the document is not <xsd:schema>.错误