Delphi Language Guide Delphi for Microsoft Win32 Delphi for the Microsoft. Net framework



Yüklə 0,84 Mb.
Pdf görüntüsü
səhifə199/294
tarix02.01.2022
ölçüsü0,84 Mb.
#41395
1   ...   195   196   197   198   199   200   201   202   ...   294
DelphiLanguageGuide

Text File Device Drivers
You can define your own text file device drivers for your programs. A text file device driver is a set of four functions
that completely implement an interface between Delphi's file system and some device.
The four functions that define each device driver are Open, InOut, Flush, and Close. The function header of each
function is
function DeviceFunc(var F: TTextRec): Integer;
where DeviceFunc is the name of the function (that is, Open, InOut, Flush, or Close). The return value of a device-
interface function becomes the value returned by IOResult. If the return value is zero, the operation was successful.
To associate the device-interface functions with a specific file, you must write a customized Assign procedure. The
Assign procedure must assign the addresses of the four device-interface functions to the four function pointers in
the text file variable. In addition, it should store the fmClosedmagic constant in the Mode field, store the size of the
text file buffer in BufSize, store a pointer to the text file buffer in BufPtr, and clear the Name string.
Assuming, for example, that the four device-interface functions are called DevOpen, DevInOut, DevFlush, and
DevClose, the Assign procedure might look like this:
procedure AssignDev(var F: Text);
  begin
   with TTextRec(F) do
   begin
    Mode := fmClosed;
172


    BufSize := SizeOf(Buffer);
    BufPtr := @Buffer;
    OpenFunc := @DevOpen;
    InOutFunc := @DevInOut;
    FlushFunc := @DevFlush;
    CloseFunc := @DevClose;
    Name[0] := #0;
   end;
  end;
The device-interface functions can use the UserData field in the file record to store private information. This field
isn't modified by the product file system at any time.

Yüklə 0,84 Mb.

Dostları ilə paylaş:
1   ...   195   196   197   198   199   200   201   202   ...   294




Verilənlər bazası müəlliflik hüququ ilə müdafiə olunur ©azkurs.org 2024
rəhbərliyinə müraciət

gir | qeydiyyatdan keç
    Ana səhifə


yükləyin