iValue := 1234;
strFile := 'c:\1.txt';//已经存在但为空!
fHandle := FileOpen( strFile, fmOpenWrite );
FileSeek( fHandle, 0, 0);//point to the end of file
strValue := IntToStr( iValue ) + ' ';
FileWrite( fHandle, strValue , sizeof(strValue) );
FileClose( fHandle );
其中 iValue : integer;
strPath, strFile, strValue : string;
fHandle : Integer;
按理c:\1.txt应该有内容为:1234,可是没有!为什么?难道File×这一套不管用?
strFile := 'c:\1.txt';//已经存在但为空!
fHandle := FileOpen( strFile, fmOpenWrite );
FileSeek( fHandle, 0, 0);//point to the end of file
strValue := IntToStr( iValue ) + ' ';
FileWrite( fHandle, strValue , sizeof(strValue) );
FileClose( fHandle );
其中 iValue : integer;
strPath, strFile, strValue : string;
fHandle : Integer;
按理c:\1.txt应该有内容为:1234,可是没有!为什么?难道File×这一套不管用?
解决方案 »
- Delphi 有没有直接写网页的功能?
- 关于Dbgrid中显示方式的问题?
- 用Select from where语句从一个表中选中几个纪录如何把它们移到表头去啊,请大家帮忙,谢谢(最好用sql)
- 找工作.....
- 實在是沒分了﹐但是還有好多問題
- ●●●高分求教!!!Delphi中问题,没有人知道吗?
- 问题又没了!这个问题可以说是大家来评理!痛苦中。。。。
- 能否自定义StringGrid任意格子的字体属性吗?
- 散分了,各位大虾们,辛苦了!先祝你们春节愉快,另问个小问题:sqlserver写的存储过程如何用delphi启用?
- 我想把一些控件改成继承于我自己的控件类该怎么做啊?
- 请教类似于VB中的选择小方框的列表框,如何设置ListBox的属性?
- 大家觉得那款报表控件比较好用?
t :TextFile;
begin
AssignFile(t, 'C:\1.txt');
Rewrite(t);
try
Writeln(t, '1234');
finally
CloseFile(t);
end;
end;
var
iValue : integer;
strPath, strFile, strValue : string;
fHandle : Integer;
sV:array [1..4] of char;//用字符数组
begin
iValue := 1234;
strFile := 'c:\1.txt';//已经存在但为空!
fHandle := FileOpen( strFile, fmOpenWrite );
FileSeek( fHandle, 0, 0);//point to the end of file
strValue := '1234';
sv:='1234';
FileWrite( fHandle, sv , High(sv));;//用字符数组
FileClose( fHandle );
end;
FileWrite( fHandle, '1234' , sizeof('1234') );
其实STRING类型的第一个字节记录了字符串的长度。
你可以把strValue[0]的值取出来看看是多少?别告诉我不知道呀!给你几种方法解决你的问题:
1、FileWrite(fHandle, strValue[1] , Length(StrValue));//注意不是Sizeof2、定义 buf : PChar;
StrLen : Integer;
iValue := 1234;
strFile := 'c:\1.txt';//
fHandle := FileOpen( strFile, fmOpenWrite );
FileSeek( fHandle, 0, 0);//point to the end of file
strValue := IntToStr( iValue ) + ' ';StrLen := Length(strValue);
getmem(buf,StrLen); //获取内存缓冲区
copyMemory(buf,Pchar(strValue),StrLen); //拷贝strValue到buf中.
FileWrite( fHandle,Buf^,StrLen);
FileClose( fHandle );
freeMem(buf); //释放内存