function TTranPrn.Print(Var JobId:integer) :boolean;
var
pFileName
Char;
pDocName
Char;
pPrnName
AnsiChar;
hPrinter:THandle;
DocInfo:TDocInfo1A;
tmp:array[0..7] of Char;
wcnt
WORD;
s:string;
f:file;
i:integer;
begin
// event, before printe
if Assigned(f_OnBeforePrint) then
f_OnBeforePrint(self);
// set value.
pFileName := PChar(f_FileName);
// file name.
pDocName := PChar(f_DocumentName);
//do
cument name.
pPrnName := PAnsiChar(f_PrinterName);
// printer name.
// checkdo
cument name.
if pDocName^ = #0 then
pDocName := pFileName;
// get printer handle.
if OpenPrinterA( pPrnName,hPrinter,nil ) = False then
begin
ErrorEvent(F_OnOpenPrinterError, 'Error:OpenPrinter!' );
Result := False;
exit;
end;
// initdo
cInfo.
do
cInfo.pDocName := pDocName;
//do
cument name.
do
cInfo.pOutputFile := NIL;
// output filename.
do
cInfo.pDatatype := NIL;
// data type.
// open file.
try
AssignFile( f, pFileName );
Reset( f, 1 );
except
ErrorEvent(F_OnOpenFileError, 'Error:OpenFile!' );
Result := False;
exit;
end;
// start print spool.do
cInfo structure 1 type. NT3.51 only type 1.
JObID:= StartDocPrinterA( hPrinter,1,@DocInfo);
if JObID= 0 then
begin
ErrorEvent( F_OnStartDocPrinterError, 'Error:StartDocPrinter!');
Result := False;
exit;
end;
// loop of reading file and spooling file.
while not eof(f)do
begin
// process.
application.ProcessMessages;
// read byte.
i := 1;
BlockRead( f, tmp, i );
// event, After printe
if Assigned(f_OnAfterReadByte) then
f_OnAfterReadByte(self);
// set printer spooler
if WritePrinter( hPrinter, @tmp, i, wcnt ) = False then
begin
ErrorEvent( F_OnWritePrinterError, 'Error:WritePrinter!');
AbortPrinter( hPrinter );
EndDocPrinter( hPrinter);
ClosePrinter( hPrinter );
Result := False;
exit;
end;
end;
// close file
CloseFile(f);
// end spool.
// If the function fails, the return value should be FALSE.
// To get extended error information, call GetLastError.
Result := EndDocPrinter(hPrinter);
if not Result then
ErrorEvent( F_OnWritePrinterError, 'Error:EndDocPrinter!');
// close printer handle.
ClosePrinter( hPrinter );
// event, After print
if Result and Assigned(f_OnAfterPrint) then
f_OnAfterPrint(self);
end;