I have a problem, I use akind of passthrough printing.
Sometime after I print 5-6 pages then I have
an Out Of Resources error.
I want to ask is:
Is each Escape function exist in below sub-routine
take 1 resource each time called?
interface
uses printers, Windows, WinProcs, WinTypes, SysUtils;
procedure TRawprinter.write (const S: string);
var pass: passrec;
begin
pass.L := Length(S);
StrPCopy(pass.S, S);
Escape(dc2, PASSTHROUGH, 0, @pass, nil);
end;
Is is true that Out Of Resource error ocurred
because I am to frequently call above function?
Thanks
Rusmin Noer
>I have a problem, I use akind of passthrough printing.
>Sometime after I print 5-6 pages then I have
>an Out Of Resources error.
Is this Delphi 1.0? I don't think you have a resource problem, but you
may have a problem with your passrec type. How is it declared?
-Steve
unit Rawprinter;
{ from Gnome http://www.gnomehome.demon.nl/uddf/index.htm}
interface
uses printers, Windows, WinProcs, WinTypes, SysUtils;
type TRawprinter = class(TPrinter)
public
dc2: HDC;
procedure startraw(var adaError: Boolean);
procedure endraw;
procedure write (const S: string);
procedure writeln(const S: string);
end;
implementation
uses Forms;
function AbortProc(Prn: HDC; Error: Integer): BOOL; stdcall;
begin
Application.ProcessMessages;
Result := not Printer.Aborted;
end;
type
TPrinterDevice = class
DRIVER, Device, PORT: string;
constructor Create(ADriver, ADevice, APort: PChar);
function IsEqual(ADriver, ADevice, APort: PChar): Boolean;
end;
constructor TPrinterDevice.Create(ADriver, ADevice, APort: PChar);
begin
inherited Create;
DRIVER := ADriver;
Device := ADevice;
PORT := APort;
end;
function TPrinterDevice.IsEqual(ADriver, ADevice, APort: PChar): Boolean;
begin
Result := (Device = ADevice) and (PORT = APort);
end;
{$HINTS OFF}
procedure TRawprinter.startraw(var adaError: Boolean);
var
CTitle : array[0..31] of Char;
CMode : array[0..4] of Char;
DocInfo: TDocInfo;
R : Integer;
begin
try
StrPLCopy(CTitle, Title, SizeOf(CTitle) - 1);
StrPCopy(CMode, 'RAW');
FillChar(DocInfo, SizeOf(DocInfo), 0);
with DocInfo do
begin
cbSize := SizeOf(DocInfo);
lpszDocName := CTitle;
lpszOutput := nil;
lpszDatatype := CMode;
end;
with TPrinterDevice(printers.Objects[PrinterIndex]) do
begin
dc2 := CreateDC(PChar(DRIVER), PChar(Device), PChar(PORT), nil);
end;
SetAbortProc(dc2, AbortProc);
R := StartDoc(dc2, DocInfo);
except
adaError := True;
end;
end;
{$HINTS ON}
{$HINTS OFF}
procedure TRawprinter.endraw;
var R: Integer;
begin
R := Windows.EndDoc(dc2);
end;
{$HINTS ON}
type passrec = packed record
L: Word;
S: array[0..255] of Char;
end;
procedure TRawprinter.write (const S: string);
var pass: passrec;
begin
pass.L := Length(S);
StrPCopy(pass.S, S);
Escape(dc2, PASSTHROUGH, 0, @pass, nil);
end;
procedure TRawprinter.writeln(const S: string);
var pass: passrec;
begin
pass.L := Length(S) + 2;
StrPCopy(pass.S, S + #13#10);
Escape(dc2, PASSTHROUGH, 0, @pass, nil);
end;
end.
----------------------------------------------------------------------------
--------
The main program call the sub rutine like:
uses
RawPrinter;
var
Myprinter : TRawPrinter;
procedure TfmStockPrint1.bbPrintClick(Sender: TObject);
begin
<blah>
try
Myprinter := TRawPrinter.Create;
<blah>
try
Myprinter.startraw(AdaError);
Print1(Sender);
finally
Myprinter.endraw;
end;
finally
MyPrinter.Free;
end;
end;
procedure TfmStockPrint1.Print1(Sender: TObject);
begin
<blah-blah>
< for a lot of stock do >
PrinterWrite('............');
<So many PrinterWrite('............'); >
PrinterWriteln;
end;
procedure TfmStockPrint1.PrinterWrite(AString: string);
begin
Myprinter.write (AString);
end;
procedure TfmStockPrint1.PrinterWriteln(AString: string);
begin
Myprinter.Writeln(AString);
end;
----------------------------------------------------------------------------
-------------------------------
I am using Delphi 3.0
I download the source code from
http://www.gnomehome.demon.nl/uddf/index.htm
It's a good sub-routine, it print very fast/direct to dot-matrix printer.
and also can spool in the PrinterQueue .
The problem is:
After 5-6 reports printing together, when my report is on the
PrinterQueue/spooling,
then I get an Out Of Resources error!
What I want to ask is:
IS THE EACH OF
Escape(dc2, PASSTHROUGH, 0, @pass, nil);
TAKE ONE RESOURCE FROM MY COMPUTER ?
if true then
I will not call so often use above statement.
I will make a kind of buffer, and I will change
all the Write to only one Writeln, so I can spare the Resources.
In my mind is: when the report in PrinterQueue then the computer
is still holding the resource. Is it true?
If I print 2-3 report together, then after finish, I print again 2-3
report,
the error did not exist! All together is about 50 report! The report is the
same
report, but it printed 50 times, because the Stock have so many category
to print.
I have ask this before, in this newsgroup for memory leak, but a couple of
nice guy told me that the sub-routine have no memory leak.
I dont know anything about Winapi programming.
Sorry, my letter is soo long.
However, thanks.
Season Greetings.
Rusmin Noer
Rusmin Noer wrote in message <7603io$h2...@forums.borland.com>...
>The Complete Source is :
As Paul says, I think the problem is with the device context.
-Steve
Do you have sub routine to check
"The remain/available resources in a computer" ?
Thanks.
Rusmin Noer
in Borland TI_LIST
http://www.borland.co.uk/devsupport/delphi/ti_list/TI3231.html
I will try to check the code my self.
However thanks alot.
Rusmin Noer
Rusmin Noer wrote in message <7626et$i6...@forums.borland.com>...