mirror of
https://gitlab.com/freepascal.org/fpc/source.git
synced 2025-04-15 12:41:37 +02:00
+ Added some stuff from todo list:
- array of const - val/read also do rangechecking - don't change pointer used in WITH statement - GetLongName/GetshortName - Size of sets is 4 bytes - Rewrite opens write-only - StringOfChar documented
This commit is contained in:
parent
d5cb06237a
commit
990d7987f1
45
docs/dos.tex
45
docs/dos.tex
@ -585,6 +585,49 @@ i.e. it does nothing.
|
||||
\SeeAlso
|
||||
\seep{SetIntVec}
|
||||
\end{procedure}
|
||||
|
||||
\begin{function}{GetLongName}
|
||||
\Declaration
|
||||
function GetLongName(var p : String) : boolean;
|
||||
\Description
|
||||
This function is only implemented in the GO32V2 version of \fpc.
|
||||
|
||||
\var{GetLongName} changes the filename \var{p} to a long filename
|
||||
if the \dos call to do this is successful. The resulting string
|
||||
is the long file name corresponding to the short filename \var{p}.
|
||||
|
||||
The function returns \var{True} if the \dos call was successful,
|
||||
\var{False} otherwise.
|
||||
|
||||
This function should only be necessary when using the DOS extender
|
||||
under Windows 95 and higher.
|
||||
\errors
|
||||
If the \dos call was not succesfull, \var{False} is returned.
|
||||
\seealso
|
||||
\seef{GetShortName}
|
||||
\end{function}
|
||||
|
||||
\begin{function}{GetShortName}
|
||||
\Declaration
|
||||
function GetShortName(var p : String) : boolean;
|
||||
\Description
|
||||
This function is only implemented in the GO32V2 version of \fpc.
|
||||
|
||||
\var{GetShortName} changes the filename \var{p} to a short filename
|
||||
if the \dos call to do this is successful. The resulting string
|
||||
is the short file name corresponding to the long filename \var{p}.
|
||||
|
||||
The function returns \var{True} if the \dos call was successful,
|
||||
\var{False} otherwise.
|
||||
|
||||
This function should only be necessary when using the DOS extender
|
||||
under Windows 95 and higher.
|
||||
\errors
|
||||
If the \dos call was not successful, \var{False} is returned.
|
||||
\seealso
|
||||
\seef{GetLongName}
|
||||
\end{function}
|
||||
|
||||
\begin{procedurel}{GetTime}{Dos:GetTime}
|
||||
\Declaration
|
||||
Procedure GetTime (var hour, minute, second, sec100: word);
|
||||
@ -600,8 +643,10 @@ None.
|
||||
\seepl{GetDate}{Dos:GetDate},
|
||||
\seep{SetTime}
|
||||
\end{procedurel}
|
||||
|
||||
\latex{\lstinputlisting{dosex/ex3.pp}}
|
||||
\html{\input{dosex/ex3.tex}}
|
||||
|
||||
\begin{procedure}{GetVerify}
|
||||
\Declaration
|
||||
Procedure GetVerify (var verify: boolean);
|
||||
|
@ -29,11 +29,11 @@
|
||||
%\input{crt.tex}
|
||||
%\input{dos.tex}
|
||||
%\input{getopts.tex}
|
||||
\input{go32.tex}
|
||||
%\input{go32.tex}
|
||||
%\input{graph.tex}
|
||||
%\input{heaptrc.tex}
|
||||
%\input{ipc.tex}
|
||||
%\input{linux.tex}
|
||||
\input{ide.tex}
|
||||
%\input{mmx.tex}
|
||||
%\input{mouse.tex}
|
||||
%\input{objects.tex}
|
||||
|
@ -878,8 +878,9 @@ The \var{\{\$RANGECHECKS OFF\}} switch tells the compiler not to generate range
|
||||
code. This may result in faulty program behaviour, but no run-time errors
|
||||
will be generated.
|
||||
|
||||
\begin{remark} Range checking for sets and enumerations are not yet fully
|
||||
implemented.
|
||||
\begin{remark}
|
||||
\item The standard functions \var{val} and \var{Read} will also check ranges
|
||||
when the call is compiled in \var{\{\$R+\}} mode.
|
||||
\end{remark}
|
||||
|
||||
\subsection{\var{\$SATURATION} : Saturation operations}
|
||||
|
160
docs/ref.tex
160
docs/ref.tex
@ -464,7 +464,7 @@ Type
|
||||
X,Y : Real
|
||||
end;
|
||||
Const
|
||||
Origin : Point = (X:0.0 , Y:0.0);
|
||||
Origin : Point = (X:0.0; Y:0.0);
|
||||
\end{verbatim}
|
||||
The order of the fields in a constant record needs to be the same as in the type declaration,
|
||||
otherwise you'll get a compile-time error.
|
||||
@ -2910,7 +2910,8 @@ Program testw;
|
||||
Type AR = record
|
||||
X,Y : Longint;
|
||||
end;
|
||||
|
||||
PAR = Record;
|
||||
|
||||
Var S,T : Ar;
|
||||
begin
|
||||
S.X := 1;S.Y := 1;
|
||||
@ -2925,6 +2926,29 @@ The output of this program is
|
||||
\end{verbatim}
|
||||
Showing thus that the \var{X,Y} in the \var{WriteLn} statement match the
|
||||
\var{T} record variable.
|
||||
|
||||
\begin{remark}
|
||||
If you use a \var{With} statement with a pointer, or a class, it is not
|
||||
permitted to change the pointer or the class in the \var{With} block.
|
||||
With the definitions of the previous example, the following illiustrates
|
||||
what it is about:
|
||||
\begin{verbatim}
|
||||
|
||||
Var p : PAR;
|
||||
|
||||
begin
|
||||
With P^ do
|
||||
begin
|
||||
// Do some operations
|
||||
P:=OtherP;
|
||||
X:=0.0; // Wrong X will be used !!
|
||||
end;
|
||||
\end{verbatim}
|
||||
The reason the pointer cannot be changed is that the address is stored
|
||||
by the compiler in a temporary register. Changing the pointer won't change
|
||||
the temporary address. The same is true for classes.
|
||||
\end{remark}
|
||||
|
||||
\subsection{Exception Statements}
|
||||
As of version 0.99.7, \fpc supports exceptions. Exceptions provide a
|
||||
convenient way to program error and error-recovery mechanisms, and are
|
||||
@ -3102,7 +3126,118 @@ begin
|
||||
Average := Temp / (High(Row)+1);
|
||||
end;
|
||||
\end{verbatim}
|
||||
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|
||||
% The array of const construct
|
||||
\subsection{Array of const}
|
||||
In Object Pascal or Delphi mode, \fpc supports the \var{Array of Const}
|
||||
construction to pass parameters to a subroutine.
|
||||
|
||||
This is a special case of the \var{Open array} construction, where you
|
||||
are allowed to pass any expression in an array to a function or procedure.
|
||||
|
||||
In the procedure, passed the arguments can be examined using a special
|
||||
record:
|
||||
\begin{verbatim}
|
||||
Type
|
||||
PVarRec = ^TVarRec;
|
||||
TVarRec = record
|
||||
case VType : Longint of
|
||||
vtInteger : (VInteger: Longint);
|
||||
vtBoolean : (VBoolean: Boolean);
|
||||
vtChar : (VChar: Char);
|
||||
vtExtended : (VExtended: PExtended);
|
||||
vtString : (VString: PShortString);
|
||||
vtPointer : (VPointer: Pointer);
|
||||
vtPChar : (VPChar: PChar);
|
||||
vtObject : (VObject: TObject);
|
||||
vtClass : (VClass: TClass);
|
||||
vtAnsiString : (VAnsiString: Pointer);
|
||||
vtWideString : (VWideString: Pointer);
|
||||
vtInt64 : (VInt64: PInt64);
|
||||
end;
|
||||
\end{verbatim}
|
||||
Inside the procedure body, the array of const is equivalent to
|
||||
an open array of TVarRec:
|
||||
\begin{verbatim}
|
||||
Procedure Testit (Args: Array of const);
|
||||
|
||||
Var I : longint;
|
||||
|
||||
begin
|
||||
If High(Args)<0 then
|
||||
begin
|
||||
Writeln ('No aguments');
|
||||
exit;
|
||||
end;
|
||||
Writeln ('Got ',High(Args)+1,' arguments :');
|
||||
For i:=0 to High(Args) do
|
||||
begin
|
||||
write ('Argument ',i,' has type ');
|
||||
case Args[i].vtype of
|
||||
vtinteger :
|
||||
Writeln ('Integer, Value :',args[i].vinteger);
|
||||
vtboolean :
|
||||
Writeln ('Boolean, Value :',args[i].vboolean);
|
||||
vtchar :
|
||||
Writeln ('Char, value : ',args[i].vchar);
|
||||
vtextended :
|
||||
Writeln ('Extended, value : ',args[i].VExtended^);
|
||||
vtString :
|
||||
Writeln ('ShortString, value :',args[i].VString^);
|
||||
vtPointer :
|
||||
Writeln ('Pointer, value : ',Longint(Args[i].VPointer));
|
||||
vtPChar :
|
||||
Writeln ('PCHar, value : ',Args[i].VPChar);
|
||||
vtObject :
|
||||
Writeln ('Object, name : ',Args[i].VObject.Classname);
|
||||
vtClass :
|
||||
Writeln ('Class reference, name :',Args[i].VClass.Classname);
|
||||
vtAnsiString :
|
||||
Writeln ('AnsiString, value :',AnsiString(Args[I].VAnsiStr
|
||||
else
|
||||
Writeln ('(Unknown) : ',args[i].vtype);
|
||||
end;
|
||||
end;
|
||||
end;
|
||||
\end{verbatim}
|
||||
In your code, it is possible to pass an arbitrary array of elements
|
||||
to this procedure:
|
||||
\begin{verbatim}
|
||||
S:='Ansistring 1';
|
||||
T:='AnsiString 2';
|
||||
Testit ([]);
|
||||
Testit ([1,2]);
|
||||
Testit (['A','B']);
|
||||
Testit ([TRUE,FALSE,TRUE]);
|
||||
Testit (['String','Another string']);
|
||||
Testit ([S,T]) ;
|
||||
Testit ([P1,P2]);
|
||||
Testit ([@testit,Nil]);
|
||||
Testit ([ObjA,ObjB]);
|
||||
Testit ([1.234,1.234]);
|
||||
TestIt ([AClass]);
|
||||
\end{verbatim}
|
||||
|
||||
If the procedure is declared with the \var{cdecl} modifier, then the
|
||||
compiler will pass the array as a C compiler would pass it. This, in effect,
|
||||
emulates the C construct of a varable number of arguments, as the following
|
||||
example will show:
|
||||
\begin{verbatim}
|
||||
program testaocc;
|
||||
{$mode objfpc}
|
||||
|
||||
Const
|
||||
P : Pchar = 'example';
|
||||
Fmt : PChar =
|
||||
'This %s uses printf to print numbers (%d) and strings.'#10;
|
||||
|
||||
// Declaration of standard C function printf:
|
||||
procedure printf (fm : pchar; args : array of const);cdecl; external 'c';
|
||||
|
||||
begin
|
||||
printf(Fmt,[P,123]);
|
||||
end.
|
||||
\end{verbatim}
|
||||
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|
||||
% Function overloading
|
||||
\section{Function overloading}
|
||||
@ -5606,6 +5741,7 @@ the optional parameter \var{L}. Default a value of 128 is used.
|
||||
if \var{Rewrite} finds a file with the same name as \var{F}, this file is
|
||||
truncated to length \var{0}. If it doesn't find such a file, a new file is
|
||||
created.
|
||||
|
||||
\Errors
|
||||
If the file cannot be opened for writing, then a run-time error is
|
||||
generated. This behavior can be changed by the \var{\{\$i\} } compiler switch.
|
||||
@ -5923,6 +6059,26 @@ None.
|
||||
|
||||
\FPCexample{ex68}
|
||||
|
||||
\begin{function}{StringOfChar}
|
||||
\Declaration
|
||||
Function StringOfChar(c : char;l : longint) : AnsiString;
|
||||
\Description
|
||||
\var{StringOfChar} creates a new Ansistring of length \var{l} and fills
|
||||
it with the character \var{c}.
|
||||
|
||||
It is equivalent to the following calls:
|
||||
\begin{verbatim}
|
||||
SetLength(StringOfChar,l);
|
||||
FillChar(Pointer(StringOfChar)^,Length(StringOfChar),c);
|
||||
\end{verbatim}
|
||||
\Errors
|
||||
None.
|
||||
\SeeAlso
|
||||
\seep{SetLength}
|
||||
\end{function}
|
||||
|
||||
\FPCexample{ex97}
|
||||
|
||||
\begin{function}{Succ}
|
||||
\Declaration
|
||||
Function Succ (X : Any ordinal type) : Same type;
|
||||
|
@ -1410,6 +1410,7 @@ Pascal language.
|
||||
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|
||||
% Things that will not work
|
||||
\section{Things that will not work}
|
||||
|
||||
Here we give a list of things which are defined/allowed in Turbo Pascal, but
|
||||
which are not supported by \fpc. Where possible, we indicate the reason.
|
||||
\begin{enumerate}
|
||||
@ -1447,10 +1448,13 @@ list of all reserved words.)
|
||||
\item Compiler switches and directives are mostly the same, but some extra
|
||||
exist.
|
||||
\item Units are not binary compatible.
|
||||
\item Sets are always 4 bytes in Free Pascal; this means that some typecasts
|
||||
which were possible in Turbo Pascal are no longer possible in Free Pascal.
|
||||
\item A file is opened for output only (using \var{fmOutput}) when it is
|
||||
opened with \var{Rewrite}. In order to be able to read from it, it should
|
||||
be reset with \seep{Reset}.
|
||||
\end{enumerate}
|
||||
|
||||
|
||||
|
||||
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|
||||
% Things which are extra
|
||||
\section{Things which are extra}
|
||||
|
Loading…
Reference in New Issue
Block a user