什么最容易地建立和拯救条形(txt
文档?
my delphi 2009 app has a basic translation system that uses GNUGetText. i had used some win API calls to prepare the fonts. i thought it was working correctly until recently when someone from Malta ...
什么最容易地建立和拯救条形(txt
文档?
使用<代码>TStringList。
uses
Classes, Dialogs; // Classes for TStrings, Dialogs for ShowMessage
var
Lines: TStrings;
Line: string;
FileName: string;
begin
FileName := test.txt ;
Lines := TStringList.Create;
try
Lines.Add( First line );
Lines.Add( Second line );
Lines.SaveToFile(FileName);
Lines.LoadFromFile(FileName);
for Line in Lines do
ShowMessage(Line);
finally
Lines.Free;
end;
end;
Also SaveToFile
and LoadFromFile
can take an additional Encoding in Delphi 2009 and newer to set the text encoding (Ansi, UTF-8, UTF-16, UTF-16 big endian).
实际上,我更喜欢:
var
Txt: TextFile;
SomeFloatNumber: Double;
SomeStringVariable: string;
Buffer: Array[1..4096] of byte;
begin
SomeStringVariable := Text ;
AssignFile(Txt, Some.txt );
Rewrite(Txt);
SetTextBuf(Txt, Buffer, SizeOf(Buffer));
try
WriteLn(Txt, Hello, World. );
WriteLn(Txt, SomeStringVariable);
SomeFloatNumber := 3.1415;
WriteLn(Txt, SomeFloatNumber:0:2); // Will save 3.14
finally CloseFile(Txt);
end;
end;
I consider this the easiest way, since you don t need the classes or any other unit for this code. And it works for all Delphi versions including -if I m not mistaken- all .NET versions of Delphi...
我在此举了一个例子,叫SetaTextBuf(SetaTextBuf),这是大大加快Delphi案卷的良好骗局。 通常,文本单只有128个 by。 我倾向于将这一缓冲带扩大到4096个tes。 在几个案例中,我还实施了我自己的文本类型,使我能够利用这些“console”功能,把文字写到电梯田,甚至到另一个外部应用! 在上,这个地点是我于2000年写的,刚刚修改,以确保与Delphi2007年汇编。 但无法确定新的德尔菲版本。 其后,该法典已经存在10年,即:
这些青少年功能是帕斯卡尔语的标准,自此开始,我并不期望他们很快会消失。 “TtextRec”类可能在今后加以修改,但因此,我可以预测该法典今后是否会奏效。 一些解释:
http://creativecommons.org/licenses/by/3.0/“rel=“nofollow noreferer”>CC-BY
Oh是ZIP档案的服务器,其实力很强,因此,它往往每天被击落几次。 与此有关。
在2010年德尔菲斯启用的IOUtils单位为撰写/阅读文本档案提供了一些非常方便的职能:
//add the text Some text to the file C:usersdocuments est.txt :
TFile.AppendAllText( C:usersdocuments ext.txt , Some text , TEncoding.ASCII);
或者如果你使用较旧的德尔菲(没有<条码>的条码>,则使用条码>。 2. 重述清单的方法:
var i : integer;
begin
...
try
Lines.Add( First line );
Lines.Add( Second line );
Lines.SaveToFile(FileName);
Lines.LoadFromFile(FileName);
for i := 0 to Lines.Count -1 do
ShowMessage(Lines[i]);
finally
Lines.Free;
end;
如果您重新使用Delphi版本,到2009年,请查阅TStreamWriter
。
还将关注文本文档编码和新线特性。
procedure String2File;
var s:ansiString;
begin
s:= My String ;
with TFileStream.create( c:myfile.txt ,fmCreate) do
try
writeBuffer(s[1],length(s));
finally
free;
end;
end;
<>Care need when using unicode strings....
my delphi 2009 app has a basic translation system that uses GNUGetText. i had used some win API calls to prepare the fonts. i thought it was working correctly until recently when someone from Malta ...
Ok, I m going nuts here. For the last (almost) four years, I ve been putting up with some extremely bad behavior from my Delphi 5 IDE. Problems include: Seemingly random errors in coride50.bpl ...
i would like to know if there are any solution to do this. Does anyone? The big picture: I want to access data over the web, using my delphi thin clients. But i´would like to keep my server/service ...
In Delphi, there is a function StrToInt() that converts a string to an integer value; there is also IntToStr(), which does the reverse. These functions doesn t appear to be part of Oxygene, and I can ...
What is the equivalent of SetLength using Oxygene? I m trying to size an integer array. var listIndexes: array of integer; begin setLength(listIndexes,5); // doesn t work end;
How can I monitor or visualize memory fragmentation of a delphi application?
I have consistently had IDE problems in Delphi/C++Builder for years, with every version. I usually just reboot, recompile, etc. and move on. However, I keep seeing others say that the IDE is rock ...
I was trying to speed up a certain routine in an application, and my profiler, AQTime, identified one method in particular as a bottleneck. The method has been with us for years, and is part of a "...