Recent

Author Topic: Printers error  (Read 13625 times)

Dibo

  • Hero Member
  • *****
  • Posts: 1061
Printers error
« on: July 23, 2005, 12:41:02 am »
I have this code:
Code: [Select]
procedure TForm2.Form2Create(Sender: TObject);
begin
Shape1.Height:=Printer.PageHeight div 5;
Shape1.Width:=Printer.PageWidth div 5;
PaintBox1.Height:=Printer.PageHeight div 5;
PaintBox1.Width:=Printer.PageWidth div 5;
end;

When I try compile i get this error: "Project project1 raised exception class 'External: SIGSEGV'"

//Return & initialize the printers list
function TPrinter.GetPrinters: TStrings;
begin
 if not Assigned(fPrinters) then
    fPrinters:=TStringList.Create;
  Result:=fPrinters;

Please answer in beginner English because i'm from Poland :D

glober

  • Full Member
  • ***
  • Posts: 130
Printers error
« Reply #1 on: July 23, 2005, 01:52:51 am »
It is probably because you are referencing 'Printer' directly. Lazarus doesn't like this. What you need to do is assign your own Printer, eg:
Code: [Select]
var MyPrinter: TPrinter;
and then do
Code: [Select]
MyPrinter := Printer;
and then use MyPrinter for your code.

Dibo

  • Hero Member
  • *****
  • Posts: 1061
Printers error
« Reply #2 on: July 23, 2005, 02:25:18 am »
Like that? :
Code: [Select]
procedure TForm2.Button1Click(Sender: TObject);
begin
MyPrinter:= Printer;
MyPrinter.Copies:=1;
MyPrinter.BeginDoc;
MyPrinter.Canvas.TextOut(20, 20, 'Hello');
MyPrinter.EndDoc;
end;

This same error. Must I use the name of my printer? This program is for sale, what if user have another name printer of my ?

glober

  • Full Member
  • ***
  • Posts: 130
Printers error
« Reply #3 on: July 23, 2005, 02:56:11 am »
'MyPrinter' can be any variable name. I just made it up as an example.

Dibo

  • Hero Member
  • *****
  • Posts: 1061
Printers error
« Reply #4 on: July 23, 2005, 03:14:47 am »
Not work. If I use MyPrinter:= Printer; my program have this same error :(

glober

  • Full Member
  • ***
  • Posts: 130
Printers error
« Reply #5 on: July 23, 2005, 03:48:30 am »
Do you have the printer4lazarus package installed ? If not try installing that. You can find it in lazarus/components/printers.

Anonymous

  • Guest
Printers error
« Reply #6 on: July 23, 2005, 04:40:18 pm »
I have installed. I think I installed it right. I only click on printer4lazarus.lpk then in the window "install", when compiled was finished my lazarus restarted automaticaly. Is it right? Why I have this error, I do this same what I do in Delphi and it work. In Lazarus I must insert "Printers" to Uses or something more? Maybe printer dialog or something else?

Dibo

  • Hero Member
  • *****
  • Posts: 1061
Printers error
« Reply #7 on: July 23, 2005, 07:45:55 pm »
I don't know what change but now is print, I put in my form printer dialog and printer setup, then I delete and it work :D . Text in paper is very very small but I have Font size 14 - why? I see, that lazarus dont have DrawText method !! I need Wordbreak in my project :(

glober

  • Full Member
  • ***
  • Posts: 130
Printers error
« Reply #8 on: July 23, 2005, 08:05:31 pm »

Dibo

  • Hero Member
  • *****
  • Posts: 1061
Printers error
« Reply #9 on: July 24, 2005, 09:48:15 pm »
Again this same error. What is this SIGSEGV?

jesusr

  • Sr. Member
  • ****
  • Posts: 498
Printers error
« Reply #10 on: July 29, 2005, 08:08:51 am »
Quote from: "Dibo"
I don't know what change but now is print, I put in my form printer dialog and printer setup, then I delete and it work :D .


the unit printer declare a global variable: printer of type Tprinter, the problem is that this variable is uninitalized because unit printer is part of LCL, LCL should contain only plataform independant code so no windows or linux specific code can be used to initilize the printer variable.

That is the work of package Printer4Lazarus it provides an platform specific implementation, so in projects it's necesary to do

uses ..., printers, osprinters, ....

if osprinters is not found then add dependecy to package printer4lazarus in project inspector.

it happens that PrintersDlg uses unit OsPrinters so when including PrintersDlgs unit it initialize printer variable correcly and that is why it worked fine, after deleting the dialog component the unit reference is left in the uses clause and it worked ok too

Anonymous

  • Guest
Printers error
« Reply #11 on: October 14, 2005, 05:16:32 pm »
Do someone know "why approx 10 times smaller the Text on the paper", but I have Font size 14?

In LazReport the same problem:
     The Preview is looks like good, and after print it, on the paper 10x Smaller fonts!!!


Please write how can correct this.
Thanx
Ari

 

TinyPortal © 2005-2018