Preciso de ajuda com TPrinter

Delphi

02/06/2003

Vou utilizar o TPrinter numa aplicação em q desejo q, qdo eu chame o EndDoc (ou outra coisa), a impressora pare exatamente onde está, e não ejete a folha como o EndDoc faz.

Por favor, é realmente importante. : :shock:


Brigadão mesmo!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!

garibaldi


Garibaldi

Garibaldi

Curtidas 0

Respostas

Tadeu Pereira

Tadeu Pereira

02/06/2003

{
Procedimento para Definir o tamanho do papel no TPrinter.
Width = Largura do papel em centimetro * 100.
Height = Altura do papel em centimetro * 100.

Obs.: Procedimento não aceito na HP Jato de Tinta.

TPPaperSize(1500, 2940);
}
procedure PaperSize(Width, Height: LongInt);
var
Device: array[0..255] of char;
Driver: array[0..255] of char;
Port: array[0..255] of char;
hDMode: THandle;
pDMode: PDEVMODE;
begin
Printer.GetPrinter( Device, Driver, Port, hDMode);
if ( hDMode <> 0 ) then
begin
pDMode := GlobalLock( hDMode );
if ( pDMode <> nil ) then
begin
pDMode^.dmPaperSize := DMPaper_User;
pDMode^.dmPaperWidth := Width;
pDMode^.dmPaperLength := Height;
pDMode^.dmFields := pDMode^.dmFields or DM_PaperSize;
GlobalUnlock( hDMode );
end;
end;
end;

{
Função para filtrar no Listagem.DB a impressão para o TPrinter.
Impressao = Nome da listagem que se deseja filtrar.
PrnDialog = Mostra o setup da impressora

if not( TPSelect(´Bol´ + Edit2.Text, True) ) then Exit;
}
function TPSelect( Impressao: string; PrnDialog: Boolean ) : Boolean;
var
I_Cont:Integer;
begin
Result := True;
with IBDSListagem do
begin
Active := False;
SelectSQL.Clear;
SelectSQL.Add(´select * from Listagem´);
SelectSQL.Add(´where Impressao = ´´´+Impressao+´´´´);
SelectSQL.Add(´and Empresa = ´ +
´´´´+FModule.IBDSControle.FieldByName(´Empresa´).AsString+´´´´);
SelectSQL.Add(´and Impressora = ´ +
´´´´+FModule.IBDSControle.FieldByName(´Impressora´).AsString+´´´´);
SelectSQL.Add(´order by Y, X´);
Active := True;
if ( RecordCount = 0 ) then
begin
Active := False;
SelectSQL.Clear;
SelectSQL.Add(´select * from Listagem´);
SelectSQL.Add(´where Impressao = ´´´+Impressao+´´´´);
SelectSQL.Add(´and Empresa = ´´´+´All´+´´´´);
SelectSQL.Add(´and Impressora = ´ +
´´´´+FModule.IBDSControle.FieldByName(´Impressora´).AsString+´´´´);
SelectSQL.Add(´order by Y, X´);
Active := True;
if ( RecordCount = 0 ) then
begin
MessageDlg(´Impressão : ´ + Impressao +#13+
´Impressora Padrão do ´´ + Copy(S_Sistema, 1, Length( S_Sistema )-3)
+ ´´ : ´ + FModule.IBDSControle.FieldByName(´Impressora´).AsString
+13+ ´Não localizado informações para essa listagem.´ +1313+
´Para maiores informações entre em contato com seu distribuidor.´,
mtError, [mbOk], 0);
Result := False;
Exit;
end;
end;
F_Cont := RecordCount;
for I_Cont := 1 to F_Cont do
begin
L_PosX[ I_Cont ] := FieldByName(´X´).AsInteger;
L_PosY[ I_Cont ] := FieldByName(´Y´).AsInteger;
L_PosL[ I_Cont ] := FieldByName(´L´).AsInteger;
L_Campo[ I_Cont ] := FieldByName(´Campo´).AsString;
L_Tabela[ I_Cont ] := FieldByName(´Tabela´).AsString;
L_Tipo[ I_Cont ] := FieldByName(´Tipo´).AsString;
L_Precisao[ I_Cont ] := FieldByName(´Precisao´).AsString;
Next;
end;
end;
if ( PrnDialog ) then if not( FModule.PrnSetup.Execute ) then Result := False;
end;


{
Procedimento para listar com o TPrinter o filtro feito na função TPSelect();
Width = Largura do papel. | Se as duas opções forem diferentes de zero |
Height = Altura do papel. | a procedure PaperSize() será chamada. |
Orientacao = Orientação do papel( 1 = Retrato; else = Paisagem ).
PenWidth = Lagura do traço da letra.
FontStyle = Estilo da Fonte( 0 = Normal; else = Negrito ).
FontSize = Tamanho da Fonte.
FontColor = Cor da Fonte;
FontName = Nome da Fonte.
ListEnject = Para enject a folha no termino da listagem
( Não estar em funcionamento ).

Obs.: Procedimento só deve ser chamado após a função TPSelect()

TPList(0, 0, 1, 5, 0, 10, clBlack, ´Arial´, True);
}
procedure TPList( Width, Height: LongInt; Orientacao, PenWidth, FontStyle,
FontSize: Integer; FontColor: TColor; FontName: string; ListEnject: Boolean );
var
I_Cont: Integer;
begin
for I_Cont := 1 to F_Cont do
if ( L_Campo[ I_Cont ] <> ´´ ) then
begin
if ( Copy(L_Campo[ I_Cont ], 1, 1) = ´_´ ) then
L_Campo[ I_Cont ] := CaracDel( L_Campo[ I_Cont ], ´_´)
else if ( L_Tipo[ I_Cont ] = ´CN´ ) then
begin
if ( Trim( L_Precisao[ I_Cont ] ) = ´´ ) then L_Campo[ I_Cont ] :=
Format(´¬n´, [StrToFloat(L_Campo[I_Cont])])
else L_Campo[ I_Cont ] :=
Format(´¬1.´ + L_Precisao[ I_Cont ] + ´n´, [StrToFloat(L_Campo[I_Cont])])
end;
end;
if ( Width <> 0 ) and ( Height <> 0 ) then PaperSize(Width, Height);
if ( Orientacao = 1 ) then Printer.Orientation := poPortrait
else Printer.Orientation := poLandscape;
Printer.BeginDoc;
Printer.Canvas.Pen.Width := PenWidth;
Printer.Canvas.Font.Name := FontName;
if ( FontStyle = 0 ) then Printer.Canvas.Font.Style := []
else Printer.Canvas.Font.Style := [fsBold];
Printer.Canvas.Font.Size := FontSize;
Printer.Canvas.Font.Color := FontColor;
for I_Cont := 1 to F_Cont do
begin
if ( L_PosL[ I_Cont ] = 1 ) then Printer.Canvas.TextOut( L_PosX[ I_Cont ],
L_PosY[ I_Cont ], L_Campo[ I_Cont ] )
else if ( L_PosL[ I_Cont ] = 2 ) then Printer.Canvas.TextOut( L_PosX[ I_Cont ] -
( Printer.Canvas.TextWidth( L_Campo[ I_Cont ] ) div 2 ),
L_PosY[ I_Cont ], L_Campo[ I_Cont ] )
else if ( L_PosL[ I_Cont ] = 3 ) then Printer.Canvas.TextOut( L_PosX[ I_Cont ] -
Printer.Canvas.TextWidth( L_Campo[ I_Cont ] ),
L_PosY[ I_Cont ], L_Campo[ I_Cont ] );
end;
Printer.EndDoc;
end;


GOSTEI 0
Garibaldi

Garibaldi

02/06/2003

Valeu cara, poxa essa é A função hehehehe,
vou estudá-la pra colocá-la no meu programa.

muitííííííííííííssimo obrigado a vc e a todo mundo q se interessou em ler minha mensagem :D

gariballlllldi


GOSTEI 0
POSTAR