Objpas - Delphi and objfpc mode system overrides

The objpas unit is meant for compatibility with Object Pascal as implemented by Delphi. The unit is loaded automatically by the Free Pascal compiler whenever the Delphi or objfpc more is entered, either through the command line switches -Sd or -Sh or with the {$MODE DELPHI} or {$MODE OBJFPC} directives.

It redefines some basic pascal types, introduces some functions for compatibility with Delphi's system unit, and introduces some methods for the management of the resource string tables.

Enumeration callback type for resource strings

The resource string tables can be managed with a callback function which the user must provide: TResourceIterator.

Assign text or untyped file

AssignFile is completely equivalent to the system unit's Assign function: It assigns Name to a function of any type (FileType can be Text or a typed or untyped File variable). Name can be a string, a single character or a PChar.

It is most likely introduced to avoid confusion between the regular Assign function and the Assign method of TPersistent in the Delphi VCL.

None.
Close text or untyped file

CloseFile flushes and closes a file F of any file type. F can be Text or a typed or untyped File variable. After a call to CloseFile, any attempt to write to the file F will result in an error.

It is most likely introduced to avoid confusion between the regular Close function and the Close method of TForm in the Delphi VCL.

for an example, see .

None.
Free memory

FreeMem releases the memory reserved by a call to GetMem. The (optional) Size parameter is ignored, since the object pascal version of GetMem stores the amount of memory that was requested.

Be sure not to release memory that was not obtained with the Getmem call in Objpas. Normally, this should not happen, since objpas changes the default memory manager to it's own memory manager.

None.
Allocate memory on the heap

GetMem reserves Size bytes of memory on the heap and returns a pointer to it in P. Size is stored at offset -4 of the result, and is used to release the memory again. P can be a typed or untyped pointer.

Be sure to release this memory with the FreeMem call defined in the objpas unit.

For an example, see FreeMem.

In case no more memory is available, and no more memory could be obtained from the system a run-time error is triggered. FreeMem .
Return current value of resourcestring

GetResourceStringCurrentValue returns the current value of the resourcestring in table TableIndex with index StringIndex.

The current value depends on the system of internationalization that was used, and which language is selected when the program is executed.

If either TableIndex or StringIndex are out of range, then a empty string is returned. , , , , ,
Return default (original) value of resourcestring

GetResourceStringDefaultValue returns the default value of the resourcestring in table TableIndex with index StringIndex.

The default value is the value of the string that appears in the source code of the programmer, and is compiled into the program.

If either TableIndex or StringIndex are out of range, then a empty string is returned. , , , , ,
Return hash value of resource string

GetResourceStringHash returns the hash value associated with the resource string in table TableIndex, with index StringIndex.

The hash value is calculated from the default value of the resource string in a manner that gives the same result as the GNU gettext mechanism. It is stored in the resourcestring tables, so retrieval is faster than actually calculating the hash for each string.

For an example, see .

If either TableIndex or StringIndex is zero, 0 is returned. , , , , ,
Return name of resource string.

GetResourceStringName returns the name of the resourcestring in table TableIndex with index StringIndex. The name of the string is always the unit name in which the string was declared, followed by a period and the name of the constant, all in lowercase.

If a unit MyUnit declares a resourcestring MyTitle then the name returned will be myunit.mytitle. A resourcestring in the program file will have the name of the program prepended.

The name returned by this function is also the name that is stored in the resourcestring file generated by the compiler.

Strictly speaking, this information isn't necessary for the functioning of the program, it is provided only as a means to easier translation of strings.

If either TableIndex or StringIndex is zero, an empty string is returned. , , , , ,
Create GNU Gettext hash value for a string Hash calculates the hash value of the string S in a manner that is compatible with the GNU gettext hash value for the string. It is the same value that is stored in the Resource string tables, and which can be retrieved with the function call. None. In case the calculated hash value should be 0, the returned result will be -1. , Return command-line parameter

ParamStr returns the Param-th command-line parameter as an AnsiString. The system unit function limits the result to 255 characters, and is overridden with this function.

The zeroeth command-line parameter contains the path of the executable. On some operating systems (BSD) it may be simply the command as typed on the command-line, because the OS does not offer a method to retrieve the full binary name.

For an example, see .

In case Param is an invalid value, an empty string is returned.
Re-allocate memory

ReAllocMem resizes the memory pointed to by P so it has size Size. The value of P may change during this operation. The contents of the memory pointed to by P (if any) will be copied to the new location, but may be truncated if the newly allocated memory block is smaller in size. If a larger block is allocated, only the used memory is initialized, extra memory will not be zeroed out.

Note that P may be nil, in that case the behaviour of ReAllocMem is equivalent to .

If no memory is available then a run-time error will occur.
Restore all resource strings to their declared values

ResetResourceTables resets all resource strings to their default (i.e. as in the source code) values.

Normally, this should never be called from a user's program. It is called in the initialization code of the objpas unit. However, if the resourcetables get messed up for some reason, this procedure will fix them again.

None. , , , , ,
Return number of resource strins in table

ResourceStringCount returns the number of resourcestrings in the table with index TableIndex. The strings in a particular table are numbered from 0 to ResourceStringCount-1, i.e. they're zero based.

For an example, see

If an invalid TableIndex is given, -1 is returned. , , , , , ,
Return number of resource string tables

ResourceStringTableCount returns the number of resource string tables; this may be zero if no resource strings are used in a program.

The tables are numbered from 0 to ResourceStringTableCount-1, i.e. they're zero based.

For an example, see

, , , ,
Set values of all resource strings.

SetResourceStrings calls SetFunction for all resourcestrings in the resourcestring tables and sets the resourcestring's current value to the value returned by SetFunction.

The Name,Value and Hash parameters passed to the iterator function are the values stored in the tables.

None. , , , , ,
Set value of a resource string SetResourceStringValue assigns Value to the resource string in table TableIndex with index StringIndex. , , , , , , Maximum value for type. Redefinition of integer as 32-bit type. In OBJPAS mode and in DELPHI mode, an Integer has a size of 32 bit. In TP or regular FPC mode, an integer is 16 bit. Pointer to ansistring type. Generic array of integer Alias for IntegerArray Pointer to TIntegerArray type. Generic Array of pointers. Alias for PointerArray Pointer to PointerArray Array of integer, used in interfaces. Pointer to ansistring (Delphi compatibility). Ansistring record in resource table (Delphi compatibility). Load resource string