Language:
Русский
English
RegisterBGIdriver (function) (Graph unit)
Passes the graphics system a pointer to a device driver that has been linked into an application program.
Declaration
function RegisterBGIdriver(driver: pointer): Integer;
Target
Real, Protected
Remarks
The driver must be registered before the call to InitGraph.
If an error occurs, the return value is less than 0;otherwise, the internal driver number is returned.
This routine enables a user to load a driver file and "register" the driver by passing its memory location to RegisterBGIdriver. When that driver is used by InitGraph, the registered driver will be used (instead of being loaded from disk by the Graph unit). A user-registered driver can be loaded from disk onto the heap, or converted to an .OBJ file (using BINOBJ.EXE) and linked into the .EXE.
Returns grInvalidDriver if the driver header is not recognized.
The following program loads the CGA driver onto the heap, registers it with the graphics system, and calls InitGraph:
program LoadDriv;
uses Graph;
var
Driver, Mode: Integer;
DriverF: file;
DriverP: Pointer;
begin
{ Open driver file, read into memory, register it }
Assign(DriverF, 'CGA.BGI');
Reset(DriverF, 1);
GetMem(DriverP, FileSize(DriverF));
BlockRead(DriverF, DriverP^, FileSize(DriverF));
if RegisterBGIdriver(DriverP) < 0 then
begin
Writeln('Error registering driver: ',
GraphErrorMsg(GraphResult));
Halt(1);
end;
{ Init graphics }
Driver := CGA;
Mode := CGAHi;
InitGraph(Driver, Mode, '');
if GraphResult < 0 then
Halt(1);
OutText('Driver loaded by user program');
Readln;
CloseGraph;
end.
The program begins by loading the CGA driver file from disk and registering it with the Graph unit. Then a call is made to InitGraph to initialize the graphics system. You might wish to incorporate one or more driver files directly into your .EXE file. In this way, the graphics drivers that your program needs will be built-in and only the .EXE will be needed to run. The process for incorporating a driver file into your .EXE is straight forward:
- Run BINOBJ on the driver file(s).
- Link the resulting .OBJ file(s) into your program.
- Register the linked-in driver file(s) before calling InitGraph