Here's one instance of the code, thi part finds the selected paper size
selected in a combo and sets the paper size and IDs and sets the
devmode. This is the code used with the Chars, i used to have the
getmems before the try and the freemem in the finally.
procedure TSetup.cboPaperSizeChange(Sender: TObject);
const
cchPaperName = 64;
var
Index, Needed: Integer;
PaperIDArray: array[0..cchPaperName * 100] of Char;
PaperNameArray: array[0..cchPaperName * 100] of Char;
PaperSizeArray: array[0..cchPaperName * 100] of Char;
PaperName: array[0..cchpaperName] of Char;
PaperSize: TPoint;
MyPapers: Word;
begin
PaperSize.x := 0;
PaperSize.y := 0;
if isloaded then
begin
Needed := DeviceCapabilities(pDevice, pPort,
dc_Papersize, nil, nil);
try
DeviceCapabilities(pDevice, pPort,
dc_Papernames, PaperNameArray, nil);
DeviceCapabilities(pDevice, pPort, dc_PaperSize,
PaperSizeArray, nil);
DeviceCapabilities(pdevice, pPort, dc_Papers,
PaperIDArray, nil);
for Index := 0 to Needed - 1 do
begin
//Move through the paper names until we
find the one selected
move(PaperNameArray[cchPaperName *
Index], PaperName[0], cchPaperName);
if PaperName = cboPaperSize.Text then
begin
//Get the correct paper ID and
set to devmode
move(PaperIDArray[sizeof(MyPapers) * Index], MyPapers,
sizeof(myPapers));
pDMode := GlobalLock(MyhDMode);
pDMode^.dmFields :=
pDMode^.dmFields or dm_PaperSize;
pDMode^.dmPaperSize := MyPapers;
GlobalUnlock(MyhDMode);
Printer.SetPrinter(pDevice,
pDriver, pPort, MyhDMode);
//Copy the dev mode for later
use
pDMode := GlobalLock(MyhDMode);
CopyDevModeSettings(pDMode,
MailPiecepDMode, pDevice);
GlobalUnlock(MyhDMode);
//Get the correct paper size
move(PaperSizeArray[sizeof(Papersize) * Index], PaperSize,
SizeOf(PaperSize));
//For some reason the print
drivers do not return the papersize info?
If (PaperSize.x = 0) or
(PaperSize.y = 0) then
begin
If rdoPortrait.Checked
then
begin
PaperSize.x :=
RoundUp(GetDeviceCaps(Printer.Handle, PHYSICALWIDTH) / ScaleX);
PaperSize.y :=
RoundUp(GetDeviceCaps(Printer.Handle, PHYSICALHEIGHT) / ScaleY);
end
else
begin
PaperSize.y :=
RoundUp(GetDeviceCaps(Printer.Handle, PHYSICALWIDTH) / ScaleX);
PaperSize.x :=
RoundUp(GetDeviceCaps(Printer.Handle, PHYSICALHEIGHT) / ScaleY);
end;
end;
//Copy our sizes for use later
in previews etc.
if MeasureScale = 100 then
begin
TempMailPiece.PageWidth
:= RoundUp(PaperSize.x / 2.54);
TempMailPiece.PageHeight
:= RoundUp(PaperSize.y / 2.54);
end
else
begin
TempMailPiece.PageWidth
:= PaperSize.x;
TempMailPiece.PageHeight
:= PaperSize.y;
end;
//Set the label size for
envelopes
if grpEnvelopeBarcode.Visible
then
begin
IsLoaded := False;
txtLabelWidth.Text :=
inttostr(RoundUp(TempMailPiece.PageWidth / MeasureScale));
txtLabelHeight.Text :=
inttostr(RoundUp(TempMailPiece.PageHeight / MeasureScale));
Isloaded := True;
end;
end;
end;
finally
end;
SetPreview;
SaveChanges := True;
end;
end;
-----Original Message-----
From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED]]On
Behalf Of Carl Reynolds
Sent: Monday, 9 October 2000 6:35 p.m.
To: Multiple recipients of list delphi
Subject: RE: [DUG]: Creating PChars
[Brief pause for a late lunch :-)]
> I'd love to know exactly what the problem was, so i could say, hey get
> this ***.dll and fix their problems that way. The code that generally
> gave the errors was when using DeviceCapabilities to find printer
Info,
> maybe it was just bad print drivers (this of course would not be
> un-common)?
Borlandmm.dll is the one with the shared memory manager in it, which
also
implements GetMem (details in the ShareMem unit). It's extremely
unlikely
that the problem is a corrupt borlandmm.dll, so you can probably ignore
my
comments there. :-) It's much more likely that it's a bad print driver
or
similar, although it beats me why that would be fixed when you avoided
calls
to GetMem. Something really subtle no doubt.
> Also, I didn't say that all my users had this problem, although I did
> say a lot of systems (oops), but on the machines that have had
problems,
> and I spent ages trying to sort their problems out, it all came down
to,
> if i removed the Getmem from the code it worked like a charm.
Still have the code lying around? Is it short enough to send to the
list?
Cheers,
Carl
------------------------------------------------------------------------
---
New Zealand Delphi Users group - Delphi List - [EMAIL PROTECTED]
Website: http://www.delphi.org.nz
To UnSub, send email to: [EMAIL PROTECTED]
with body of "unsubscribe delphi"
---------------------------------------------------------------------------
New Zealand Delphi Users group - Delphi List - [EMAIL PROTECTED]
Website: http://www.delphi.org.nz
To UnSub, send email to: [EMAIL PROTECTED]
with body of "unsubscribe delphi"