Well its pretty obvious that I don't know much about exception handling,
can anyone suggest a good book on exceptions etc. I just try my best to
write code that doesn't bomb out, I'd say handling the errors better
would be a betteer way, and probably faster in the long run.

Here comes a complete rewrite!

Anyway, could you look at the following and tell me what would be
incorrect about the following?

Jason

procedure TSetup.SetPaperSizeText(Update : Boolean);
const
        cchPaperName = 64;
var
        PaperNameCount, Index, Needed: Integer;
        PaperNameArray: PChar;
        PaperIDArray: PChar;
        PaperSizeArray: PChar;
        PaperSize: TPoint;
        PaperName: array[0..cchPaperName - 1] of Char;
        PaperID: Word;
begin
        //Get the number of paper name items
        PaperNameCount := DeviceCapabilities(pDevice, pPort,
dc_Papernames, nil, nil);

        if PaperNameCount = -1 then raise EDCFailed.Create('Can''t get
paper name count');

        Needed := DeviceCapabilities(pDevice, pPort, dc_PaperSize, nil,
nil);

        if Needed = -1 then raise EDCFailed.Create('Can''t get paper
size count');

        GetMem(PaperNameArray, PaperNameCount * cchPaperName);
        GetMem(PaperSizeArray, Needed * Sizeof(Word));
        GetMem(PaperIDArray, Needed * SizeOf(TPoint));

        try
                if DeviceCapabilities(pDevice, pPort, dc_Papernames,
PaperNameArray, nil) = -1 then raise EDCFailed.Create('Can''t get the
Paper names');
                if DeviceCapabilities(pDevice, pPort, dc_PaperSize,
PaperSizeArray, nil) = -1 then raise EDCFailed.Create('Can''t get the
Paper sizes');
                if DeviceCapabilities(pDevice, pPort, dc_Papers,
PaperIDArray, nil) = -1 then raise EDCFailed.Create('Can''t get the
Paper IDs');
                for Index := 0 to Needed - 1 do
                begin
                        Move(PaperIDArray[SizeOf(Word) * Index],
PaperID, SizeOf(Word));
                        if MailPiecepDMode^.dmPaperSize = PaperID then
                        begin
                                //Get the paper name
                        if Update then
                                begin
                                        Move(PaperNameArray[cchPaperName
* Index], PaperName[0], cchPaperName);
                                        cboPaperSize.ItemIndex :=
cbopaperSize.Items.IndexOf(PaperName);
                                end;

                        //Get the paper size
                                Move(PaperSizeArray[SizeOf(TPoint) *
Index], PaperSize, SizeOf(TPoint));

                                //For some reason the print drivers do
not return the papersize info?
                                If (PaperSize.x < 1) or (PaperSize.y <
1) 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;
                        end;
                end;
        finally;
                FreeMem(PaperNameArray);
                FreeMem(PaperSizeArray);
                FreeMem(PaperIDArray);
        end;
end;
---------------------------------------------------------------------------
    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"

Reply via email to