📄 help-function.txt
字号:
for Y := 0 to StringGrid1.RowCount do
begin
{ Write out the length of each string, followed by the string itself. }
StringLen := Length(StringGrid1.Cells[X,Y]);
FileWrite(FileHandle, StringLen, SizeOf(StringLen));
FileWrite(FileHandle,
StringGrid1.Cells[X,Y], Length(StringGrid1.Cells[X,Y]);//?????????/
end;
end;
FileClose(FileHandle);
end;
end;
##FileExists, RenameFile, FileCreate, FileWrite, FileClose, ExtractFileName Example
-----------------------------------------------------------------------------
FileSeek 移动档案指标位置
-----------------------------------------------------------------------------
Unit SysUtils
函数原型 function FileSeek(Handle, Offset, Origin: Integer): Integer;
说明 Origin=0读/写指标由档案开头算起.
Origin=1读/写指标由目前位置算起.
Origin=2读/写指标移动到档案结束处.
**** 功能与Dos Int 21h 插断 42h 的功能相同.
失败传回-1.
范例 procedure TForm1.Button1Click(Sender: TObject);
var
FileHandle : Integer;
FileName : String;
Buffer : PChar;
S : String;
ReadBytes : Integer;
begin
FileName:='c:\delphi_test\abc.ttt';
S:='1234567890';
if FileExists(FileName) then
FileHandle := FileOpen(FileName, fmOpenReadWrite)
else
FileHandle := FileCreate(FileName);
if FileHandle < 0 then
Begin
MessageDlg('开档失败', mtInformation, [mbOk], 0);
Exit;
End;
GetMem(Buffer, 100);
try
StrPCopy(Buffer, S);
FileWrite(FileHandle,Buffer^,10);
FileSeek(FileHandle,4,0);
ReadBytes:=FileRead(FileHandle, Buffer^, 100);
Buffer[ReadBytes]:=#0;
Label1.Caption:=IntToStr(ReadBytes)+' '+
StrPas(Buffer);
finally
FreeMem(Buffer);
end;
FileClose(FileHandle);
end;
结果 存档後abc.ttt共有1234567890等十个Bytes.
从第五位元开始读取,共读取六个位元.
567890
(位移是从0开始算起)
procedure TForm1.Button1Click(Sender: TObject);
var
iFileHandle: Integer;
iFileLength: Integer;
iBytesRead: Integer;
Buffer: PChar;
i: Integer
begin
if OpenDialog1.Execute then
begin
try
iFileHandle := FileOpen(OpenDialog1.FileName, fmOpenRead);
iFileLength := FileSeek(iFileHandle,0,2);
FileSeek(iFileHandle,0,0);
Buffer := PChar(AllocMem(iFileLength + 1));
iBytesRead = FileRead(iFileHandle, Buffer, iFileLength);
FileClose(iFileHandle);
for i := 0 to iBytesRead-1 do
begin
StringGrid1.RowCount := StringGrid1.RowCount + 1;
StringGrid1.Cells[1,i+1] := Buffer[i];
StringGrid1.Cells[2,i+1] := IntToStr(Integer(Buffer[i]));
end;
finally
FreeMem(Buffer);
end;
end;
end;
##FileOpen, FileSeek, FileRead Example
-----------------------------------------------------------------------------
FileGetAttr 档案属性
-----------------------------------------------------------------------------
Unit SysUtils
函数原型 function FileGetAttr(const FileName: string): Integer;
说明 faReadOnly = $00000001;
faHidden = $00000002;
faSysFile = $00000004;
faVolumeID = $00000008;
faDirectory = $00000010;
faArchive = $00000020;
faAnyFile = $0000003F;
范例 procedure TForm1.Button1Click(Sender: TObject);
var
S: String;
begin
S:=IntToStr(FileGetAttr('c:\delphi_d\delphi_help1.txt'));
Label1.Caption := S;
end;
-----------------------------------------------------------------------------
FileSetAttr 设定档案属性
-----------------------------------------------------------------------------
Unit SysUtils
函数原型 function FileSetAttr(const FileName: string; Attr: Integer):
Integer;
说明 设定成功传回0
-----------------------------------------------------------------------------
FindClose 结束FindFirst/FindNext
-----------------------------------------------------------------------------
procedure TForm1.Button1Click(Sender: TObject);
var
sr: TSearchRec;
FileAttrs: Integer;
begin
StringGrid1.RowCount := 1;
if CheckBox1.Checked then
FileAttrs := faReadOnly
else
FileAttrs := 0;
if CheckBox2.Checked then
FileAttrs := FileAttrs + faHidden;
if CheckBox3.Checked then
FileAttrs := FileAttrs + faSysFile;
if CheckBox4.Checked then
FileAttrs := FileAttrs + faVolumeID;
if CheckBox5.Checked then
FileAttrs := FileAttrs + faDirectory;
if CheckBox6.Checked then
FileAttrs := FileAttrs + faArchive;
if CheckBox7.Checked then
FileAttrs := FileAttrs + faAnyFile;
if FindFirst(Edit1.Text, FileAttrs, sr) = 0 then
begin
with StringGrid1 do
begin
if (sr.Attr and FileAttrs) = sr.Attr then
begin
Cells[1,RowCount-1] := sr.Name;
Cells[2,RowCount-1] := IntToStr(sr.Size);
end;
while FindNext(sr) = 0 do
begin
if (sr.Attr and FileAttrs) = sr.Attr then
begin
RowCount := RowCount + 1;
Cells[1, RowCount-1] := sr.Name;
Cells[2, RowCount-1] := IntToStr(sr.Size);
end;
end;
FindClose(sr);
end;
end;
end;
##FindFirst, FindNext, FindClose Example
-----------------------------------------------------------------------------
FindFirst 寻找第一个符合的档案.
-----------------------------------------------------------------------------
procedure TForm1.Button1Click(Sender: TObject);
var
sr: TSearchRec;
FileAttrs: Integer;
begin
StringGrid1.RowCount := 1;
if CheckBox1.Checked then
FileAttrs := faReadOnly
else
FileAttrs := 0;
if CheckBox2.Checked then
FileAttrs := FileAttrs + faHidden;
if CheckBox3.Checked then
FileAttrs := FileAttrs + faSysFile;
if CheckBox4.Checked then
FileAttrs := FileAttrs + faVolumeID;
if CheckBox5.Checked then
FileAttrs := FileAttrs + faDirectory;
if CheckBox6.Checked then
FileAttrs := FileAttrs + faArchive;
if CheckBox7.Checked then
FileAttrs := FileAttrs + faAnyFile;
if FindFirst(Edit1.Text, FileAttrs, sr) = 0 then
begin
with StringGrid1 do
begin
if (sr.Attr and FileAttrs) = sr.Attr then
begin
Cells[1,RowCount-1] := sr.Name;
Cells[2,RowCount-1] := IntToStr(sr.Size);
end;
while FindNext(sr) = 0 do
begin
if (sr.Attr and FileAttrs) = sr.Attr then
begin
RowCount := RowCount + 1;
Cells[1, RowCount-1] := sr.Name;
Cells[2, RowCount-1] := IntToStr(sr.Size);
end;
end;
FindClose(sr);
end;
end;
end;
##FindFirst, FindNext, FindClose Example
-----------------------------------------------------------------------------
FindNext 寻找下一个符合的档案.
-----------------------------------------------------------------------------
Unit SysUtils
函数原型 procedure FindClose(var F: TSearchRec);
函数原型 function FindFirst(const Path: string; Attr: Integer;
var F: TSearchRec): Integer;
函数原型 function FindNext(var F: TSearchRec): Integer;
说明 成功传回0
范例 var
SRec: TSearchRec;
procedure TForm1.SearchClick(Sender: TObject);
begin
FindFirst('c:\delphi\bin\*.*', faAnyFile, SRec);
Label1.Caption := SRec.Name + ' is ' + IntToStr(SRec.Size) +
' bytes in size';
end;
procedure TForm1.AgainClick(Sender: TObject);
begin
FindNext(SRec);
Label1.Caption := SRec.Name + ' is ' + IntToStr(SRec.Size) +
' bytes in size';
end;
procedure TForm1.FormClose(Sender: TObject);
begin
FindClose(SRec);
end
TSearchRec = record
Time: Integer;
Size: Integer;
Attr: Integer;
Name: TFileName;
xcludeAttr: Integer;
FindHandle: THandle;
FindData: TWin32FindData;
end;
============================================
Floating-point conversion routines 浮点数转换函式
============================================
FloatToDecimal 将浮点数转换为十进位数.
-----------------------------------------------------------------------------
Unit SysUtils
函数原型 procedure FloatToDecimal(var Result: TFloatRec; const Value;
ValueType: TFloatValue; Precision, Decimals: Integer);
-----------------------------------------------------------------------------
FloatToStrF 将浮点数转换为格式化字串.
-----------------------------------------------------------------------------
Unit SysUtils
函数原型 function FloatToStrF(Value: Extended; Format: TFloatFormat;
Precision,Digits: Integer): string;
-----------------------------------------------------------------------------
FloatToStr 将浮点数转换为字串.
-----------------------------------------------------------------------------
Unit SysUtils
函数原型 function FloatToStr(Value: Extended): string;
-----------------------------------------------------------------------------
FloatToText 将浮点数转换为格式化十进位.
-----------------------------------------------------------------------------
Unit SysUtils
函数原型 function FloatToText(Buffer: PChar; const Value; ValueType:
TFloatValue;Format: TFloatFormat; Precision, Digits:
Integer): Integer;
-----------------------------------------------------------------------------
FloatToTextFmt 将浮点数转换为格式化十进位.
-----------------------------------------------------------------------------
Unit SysUtils
函数原型 function FloatToTextFmt(Buffer: PChar; const Value;
ValueType: TFloatValue; Format: PChar): Integer;
-----------------------------------------------------------------------------
FormatFloat 将浮点数转换为格式化字串.
-----------------------------------------------------------------------------
Unit SysUtils
函数原型 function FormatFloat(const Format: string; Value: Extended):
string;
-----------------------------------------------------------------------------
StrToFloat 将字串转换为浮点数.
-----------------------------------------------------------------------------
Unit SysUtils
函数原型 function StrToFloat(const S: string): Extended;
范例 procedure TForm1.Button1Click(Sender: TObject);
var
Value:Double;
S:String;
begin
S:=' 1234.56 ';
Value:=StrToFloat(S);
Label1.Caption:=Format('转换为 [%9.3f]',[Value]);
end;
注意 若S字串含有非数字字元,会产生错误讯号.
-----------------------------------------------------------------------------
TextToFloat 将 null-terminated 字串转换为浮点数.
-----------------------------------------------------------------------------
Unit SysUtils
函数原型 function TextToFloat(Buffer: PChar; var Value; ValueType:
TFloatValue): Boolean;
===========================================
Flow-control routines 流程控制常式
===========================================
Break 从 for, while, or repeat 终止跳出.
-----------------------------------------------------------------------------
Unit System
函数原型 procedure Break;
范例 var
S: string;
begin
while True do
begin
ReadLn(S);
try
if S = '' then Break;
WriteLn(S);
finally
{ do something for all cases }
end;
end;
end;
-----------------------------------------------------------------------------
Continue 从 for, while, or repeat 继续执行.
-----------------------------------------------------------------------------
Unit System
函数原型 procedure Continue;
范例 var
F: File;
i: integer;
begin
for i := 0 to (FileListBox1.Items.Count - 1) do
begin
try
if FileListBox1.Selected[i] then
begin
if not FileExists(FileListBox1.Items.Strings[i]) then
begin
MessageDlg('File: ' +FileListBox1.Items.Strings[i]
+ ' not found', mtError, [mbOk], 0);
Continue;
end;
AssignFile(F, FileListBox1.Items.Strings[i]);
Reset(F, 1);
ListBox1.Items.Add(IntToStr(FileSize(F)));
CloseFile(F);
end;
finally
{ do something here }
end;
end;
end;
范例
var
F: File;
i: Integer;
begin
for i := 0 to (FileListBox1.Items.Count - 1) do begin
try
if FileListBox1.Selected[i] then
begin
if not FileExists(FileListBox1.Items.Strings[i]) then begin
MessageDlg('File: ' + FileListBox1.Items.Strings[i] +
' not found', mtError, [mbOk], 0);
Continue;
end;
AssignFile(F, FileListBox1.Items.Strings[i]);
Reset(F, 1);
ListBox1.Items.Add(IntToStr(FileSize(F)));
CloseFile(F);
end;
finally
{ do something here }
end;
end;
end;
## Continue, Items, Selected Example
-----------------------------------------------------------------------------
Exit 直接离开一个程序.
-----------------------------------------------------------------------------
Unit System
函数原型 procedure Exit;
-----------------------------------------------------------------------------
Halt 结束程式返回作业系统.
-----------------------------------------------------------------------------
Unit System
函数原型 procedure Halt [ ( Exitcode: Integer) ];
范例 begin
if 1 = 1 then
begin
if 2 = 2 then
begin
if 3 = 3 then
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -