我发现在写文件的时候,实际写的内容跟我想写的内容怎么不一样??
我简化了我的程序,原理就是取得写的内容到数组中,然后写入到文件。
下面是简化的程序,应该是写一个";本"的内容,可是结果却不是,怎么回事??
;的编码是59,本的编码177 190
请问我的实现方法有问题吗??
var
Handle:Integer;
buf:Array of Byte;
begin
setLength(buf,3);
buf[0]:=59;
buf[1]:=177;
buf[2]:=190;
Handle:=FileCreate('c:\aa.ini');
FileWrite(Handle,buf,3);
FileClose(Handle);
end;
我简化了我的程序,原理就是取得写的内容到数组中,然后写入到文件。
下面是简化的程序,应该是写一个";本"的内容,可是结果却不是,怎么回事??
;的编码是59,本的编码177 190
请问我的实现方法有问题吗??
var
Handle:Integer;
buf:Array of Byte;
begin
setLength(buf,3);
buf[0]:=59;
buf[1]:=177;
buf[2]:=190;
Handle:=FileCreate('c:\aa.ini');
FileWrite(Handle,buf,3);
FileClose(Handle);
end;
解决方案 »
- 多线程/进程tstringlist.add操作需要同步吗?
- INDY中的TIDTcpServer和TIDTcpClient有没有OnRead之类的事件?
- delphi定时器问题????
- DLL调用问题.出现"DLL为无效的WINDOWS映象.请再检测一遍您的安装盘"提示.
- 事件中的参数——Sender的问题很简单的——在线等待!
- 在线等:怎么样在delphi里面把一个存储过程写到sql-2000的master数据库里面???
- 太奇怪了,线程中创建窗体,跟踪执行没错,正常执行就出异常!!
- 用delphi 7開發,繁體'粦'字在Label,Edit中顯示'?',謝謝!
- 关于TResourceStream的问题
- 第二次重贴,高分请教高手!
- 奇怪,将ComboBox放入StringGrid中,ComboBox的下拉列表不能展开!
- 函数调用
下面这个代码可以实现,原来问题是处在FileWrite函数的使用上。
var
Handle:Integer;
buf:Array of Byte;
index:Integer;
begin
setLength(buf,1);
buf[0]:=59;
buf[1]:=177;
buf[2]:=190;
if FileExists('c:\aa.ini') then DeleteFile('c:\aa.ini');
Handle:=FileCreate('c:\aa.ini');
for index:=0 to 2 do
begin
FileSeek(Handle,0,2);
FileWrite(Handle,buf[index],1);
end;
FileClose(Handle);
end;请问能执行一次FileWrite就把数组中的内容全部写进去吗??或者有什么替代的方法把数组转换成缓冲区,然后一次写入?? 不知道我说得有人能理解不??
应该是:
FileWrite(Handle,buf[0],3);
FileWrite(Handle,buf,3);
不行,而
for index:=0 to 2 do
begin
FileSeek(Handle,0,2);
FileWrite(Handle,buf[index],1);
end;
可以呢??
FileWrite(Handle,buf,3);
那么传入的是buf本身的地址,而不是指向缓冲的首址,用buf[0]就可以了
var
Handle:Integer;
buf:Array of Byte;
begin
setLength(buf,3);
buf[0]:=59;
buf[1]:=177;
buf[2]:=190;
Handle:=FileCreate('c:\aa.ini');
FileWrite(Handle,buf[0],3);
FileClose(Handle);
end;