-----------------------------------------------------------------------------
Low 传回注脚的最小值.
-----------------------------------------------------------------------------
Unit System
函数原型 function Low(X);
说明 Ordinal type The lowest value in the range of the type
Array type The lowest value within the range of the
index type of the array
String type Returns 0
Open array Returns 0
String parameter Returns 0
-----------------------------------------------------------------------------
Ord 传回列举型态的数值.
-----------------------------------------------------------------------------
Unit System
函数原型 function Ord(X): Longint;
范例 procedure TForm1.Button1Click(Sender: TObject);
type
Colors = (RED,BLUE,GREEN);
var
S: string;
begin
S := 'BLUE has an ordinal value of ' + IntToStr(Ord(RED)) +
#13#10;
S := S+'The ASCII code for "c" is ' + IntToStr(Ord('c')) + '
decimal';
MessageDlg(S, mtInformation, [mbOk], 0);
end;
-----------------------------------------------------------------------------
Round 将实数转为整数.(有四舍五入)
-----------------------------------------------------------------------------
Unit System
函数原型 function Round(X: Extended): Longint;
范例 var
S, T: string;
begin
Str(1.4:2:1, T);
S := T + ' rounds to ' + IntToStr(Round(1.4)) + #13#10;
Str(1.5:2:1, T);
S := S + T + ' rounds to ' + IntToStr(Round(1.5)) + #13#10;
Str(-1.4:2:1, T);
S := S + T + ' rounds to ' + IntToStr(Round(-1.4)) + #13#10;
Str(-1.5:2:1, T);
S := S + T + ' rounds to ' + IntToStr(Round(-1.5));
MessageDlg(S, mtInformation, [mbOk], 0);
end;
-----------------------------------------------------------------------------
Trunc 将实数转为整数.(小数直接舍弃)
-----------------------------------------------------------------------------
Unit System
函数原型 function Trunc(X: Extended): Longint;
Untyped file routines
var
S, T: string;
begin
Str(1.4:2:1, T);
S := T + ' Truncs to ' + IntToStr(Trunc(1.4)) + #13#10;
Str(1.5:2:1, T);
S := S + T + ' Truncs to ' + IntToStr(Trunc(1.5)) + #13#10;
Str(-1.4:2:1, T);
S := S + T + ' Truncs to ' + IntToStr(Trunc(-1.4)) + #13#10;
Str(-1.5:2:1, T);
S := S + T + ' Truncs to ' + IntToStr(Trunc(-1.5));
MessageDlg(S, mtInformation, [mbOk], 0);
end;
-------------------------
var
f: file of Integer;
i,j: Integer;
begin
AssignFile(f,'TEST.INT');
Rewrite(f);
for i := 1 to 6 do
Write(f,i);
Writeln('File before truncation:');
Reset(f);
while not Eof(f) do
begin
Read(f,i);
Writeln(i);
end;
Reset(f);
for i := 1 to 3 do
Read(f,j); { Read ahead 3 records }
Truncate(f); { Cut file off here }
Writeln;
Writeln('File after truncation:');
Reset(f);
while not Eof(f) do
begin
Read(f,i);
Writeln(i);
end;
CloseFile(f);
Erase(f);
end;
-----------------------------------------------------------------------------
BlockRead 读取档案至记忆体区块.
-----------------------------------------------------------------------------
procedure TForm1.Button1Click(Sender: TObject);
var
FromF, ToF: file;
NumRead, NumWritten: Integer;
Buf: array[1..2048] of Char;
begin
if OpenDialog1.Execute then { 开档对话盒}
begin
AssignFile(FromF, OpenDialog1.FileName);{}
Reset(FromF, 1); { Record size = 1 }
if SaveDialog1.Execute then { Display Save dialog box}
begin
AssignFile(ToF, SaveDialog1.FileName);{ Open output file }
Rewrite(ToF, 1); { Record size = 1 }
Canvas.TextOut(10, 10, 'Copying ' + IntToStr(FileSize(FromF))+'bytes...');
repeat
BlockRead(FromF, Buf, SizeOf(Buf), NumRead);
BlockWrite(ToF, Buf, NumRead, NumWritten);
until (NumRead = 0) or (NumWritten <> NumRead);
CloseFile(FromF);
CloseFile(ToF);
end;
end;
end;
## BlockRead, BlockWrite, SaveDialog Example
Low 传回注脚的最小值.
-----------------------------------------------------------------------------
Unit System
函数原型 function Low(X);
说明 Ordinal type The lowest value in the range of the type
Array type The lowest value within the range of the
index type of the array
String type Returns 0
Open array Returns 0
String parameter Returns 0
-----------------------------------------------------------------------------
Ord 传回列举型态的数值.
-----------------------------------------------------------------------------
Unit System
函数原型 function Ord(X): Longint;
范例 procedure TForm1.Button1Click(Sender: TObject);
type
Colors = (RED,BLUE,GREEN);
var
S: string;
begin
S := 'BLUE has an ordinal value of ' + IntToStr(Ord(RED)) +
#13#10;
S := S+'The ASCII code for "c" is ' + IntToStr(Ord('c')) + '
decimal';
MessageDlg(S, mtInformation, [mbOk], 0);
end;
-----------------------------------------------------------------------------
Round 将实数转为整数.(有四舍五入)
-----------------------------------------------------------------------------
Unit System
函数原型 function Round(X: Extended): Longint;
范例 var
S, T: string;
begin
Str(1.4:2:1, T);
S := T + ' rounds to ' + IntToStr(Round(1.4)) + #13#10;
Str(1.5:2:1, T);
S := S + T + ' rounds to ' + IntToStr(Round(1.5)) + #13#10;
Str(-1.4:2:1, T);
S := S + T + ' rounds to ' + IntToStr(Round(-1.4)) + #13#10;
Str(-1.5:2:1, T);
S := S + T + ' rounds to ' + IntToStr(Round(-1.5));
MessageDlg(S, mtInformation, [mbOk], 0);
end;
-----------------------------------------------------------------------------
Trunc 将实数转为整数.(小数直接舍弃)
-----------------------------------------------------------------------------
Unit System
函数原型 function Trunc(X: Extended): Longint;
Untyped file routines
var
S, T: string;
begin
Str(1.4:2:1, T);
S := T + ' Truncs to ' + IntToStr(Trunc(1.4)) + #13#10;
Str(1.5:2:1, T);
S := S + T + ' Truncs to ' + IntToStr(Trunc(1.5)) + #13#10;
Str(-1.4:2:1, T);
S := S + T + ' Truncs to ' + IntToStr(Trunc(-1.4)) + #13#10;
Str(-1.5:2:1, T);
S := S + T + ' Truncs to ' + IntToStr(Trunc(-1.5));
MessageDlg(S, mtInformation, [mbOk], 0);
end;
-------------------------
var
f: file of Integer;
i,j: Integer;
begin
AssignFile(f,'TEST.INT');
Rewrite(f);
for i := 1 to 6 do
Write(f,i);
Writeln('File before truncation:');
Reset(f);
while not Eof(f) do
begin
Read(f,i);
Writeln(i);
end;
Reset(f);
for i := 1 to 3 do
Read(f,j); { Read ahead 3 records }
Truncate(f); { Cut file off here }
Writeln;
Writeln('File after truncation:');
Reset(f);
while not Eof(f) do
begin
Read(f,i);
Writeln(i);
end;
CloseFile(f);
Erase(f);
end;
-----------------------------------------------------------------------------
BlockRead 读取档案至记忆体区块.
-----------------------------------------------------------------------------
procedure TForm1.Button1Click(Sender: TObject);
var
FromF, ToF: file;
NumRead, NumWritten: Integer;
Buf: array[1..2048] of Char;
begin
if OpenDialog1.Execute then { 开档对话盒}
begin
AssignFile(FromF, OpenDialog1.FileName);{}
Reset(FromF, 1); { Record size = 1 }
if SaveDialog1.Execute then { Display Save dialog box}
begin
AssignFile(ToF, SaveDialog1.FileName);{ Open output file }
Rewrite(ToF, 1); { Record size = 1 }
Canvas.TextOut(10, 10, 'Copying ' + IntToStr(FileSize(FromF))+'bytes...');
repeat
BlockRead(FromF, Buf, SizeOf(Buf), NumRead);
BlockWrite(ToF, Buf, NumRead, NumWritten);
until (NumRead = 0) or (NumWritten <> NumRead);
CloseFile(FromF);
CloseFile(ToF);
end;
end;
end;
## BlockRead, BlockWrite, SaveDialog Example
情人太累,小姐太贵,友谊交往最实惠 ,没事开开“同学会”,拆散一对算一对!