相关疑难解决方法(0)

Writeln能否支持Unicode?

考虑这个程序:

{$APPTYPE CONSOLE}

begin
  Writeln('????????Z??????????????????????????????????????');
end.
Run Code Online (Sandbox Code Playgroud)

我的控制台上使用Consolas字体的输出是:

????????Z??????????????????????????????????????

Windows控制台非常能够支持Unicode,如此程序所示:

{$APPTYPE CONSOLE}

uses
  Winapi.Windows;

const
  Text = '????????Z??????????????????????????????????????';

var
  NumWritten: DWORD;

begin
  WriteConsole(GetStdHandle(STD_OUTPUT_HANDLE), PChar(Text), Length(Text), NumWritten, nil);
end.
Run Code Online (Sandbox Code Playgroud)

输出为:

????????Z??????????????????????????????????????

可以Writeln说服尊重Unicode,还是它固有的残缺?

windows delphi delphi-xe7

25
推荐指数
3
解决办法
3098
查看次数

Delphi:使用Reset/ReadLn替代文本文件读取

我想逐行处理文本文件.在以前我把文件加载到StringList:

slFile := TStringList.Create();
slFile.LoadFromFile(filename);

for i := 0 to slFile.Count-1 do
begin
   oneLine := slFile.Strings[i];
   //process the line
end;
Run Code Online (Sandbox Code Playgroud)

这一问题是一旦文件到达是一个几百兆,我不得不分配一个巨大的内存块; 当我真的只需要足够的内存来保持一行一行时.(另外,当系统在步骤1中锁定加载文件时,您无法真正指示进度).

我尝试使用Delphi提供的本机和推荐的文件I/O例程:

var
   f: TextFile;
begin
   Reset(f, filename);
   while ReadLn(f, oneLine) do
   begin
       //process the line
   end;
Run Code Online (Sandbox Code Playgroud)

问题Assign是没有锁定(即fmShareDenyNone)没有选项来读取文件.前一个stringlist示例也不支持no-lock,除非您将其更改为LoadFromStream:

slFile := TStringList.Create;
stream := TFileStream.Create(filename, fmOpenRead or fmShareDenyNone);
   slFile.LoadFromStream(stream);
stream.Free;

for i := 0 to slFile.Count-1 do
begin
   oneLine := slFile.Strings[i];
   //process the line
end;
Run Code Online (Sandbox Code Playgroud)

所以现在即使我没有获得锁定,我又回到将整个文件加载到内存中.

有什么替代Assign …

delphi readline text-files

12
推荐指数
1
解决办法
2万
查看次数

标签 统计

delphi ×2

delphi-xe7 ×1

readline ×1

text-files ×1

windows ×1