Ho cercato parecchio e mi par di capire che devo usare Lazreport, che però non so usare; dagli esempi si parla sempre di leggere i dati da un database, io in realtà ho un file di record, e non so come agganciarlo; ho provato a creare una stringgrid, ma non so come "buttare" i dati nell'oggetto lazreport
unit Unit1;
{$mode objfpc}{$H+}
interface
uses
Classes, SysUtils, LResources, FileUtil, LR_Class, LR_PGrid, LR_DSet, Forms,
Controls, Graphics, Dialogs, Grids, StdCtrls, DBGrids;
type
{ TForm1 }
TForm1 = class(TForm)
Button1: TButton;
frReport1: TfrReport;
StringGrid1: TStringGrid;
procedure Button1Click(Sender: TObject);
procedure FormCreate(Sender: TObject);
procedure FrPrintGrid1GetValue(const ParName: String; var ParValue: Variant
);
procedure FrPrintGrid1SetupColumn(Sender: TFrPrintGrid;
const Column: TColumn; var PrintColumn: boolean; var ColumnWidth: Integer
);
procedure frUserDataset1CheckEOF(Sender: TObject; var Eof: Boolean);
private
{ private declarations }
public
{ public declarations }
end;
var
Form1: TForm1;
implementation
{$R *.lfm}
{ TForm1 }
procedure TForm1.FormCreate(Sender: TObject);
begin
StringGrid1.Cells[1,1]:='UNO';
StringGrid1.Cells[2,2]:='DUE';
end;
procedure TForm1.FrPrintGrid1GetValue(const ParName: String;
var ParValue: Variant);
begin
end;
procedure TForm1.FrPrintGrid1SetupColumn(Sender: TFrPrintGrid;
const Column: TColumn; var PrintColumn: boolean; var ColumnWidth: Integer);
begin
end;
procedure TForm1.frUserDataset1CheckEOF(Sender: TObject; var Eof: Boolean);
begin
end;
procedure TForm1.Button1Click(Sender: TObject);
begin
frReport1.DesignReport;
frReport1.ShowReport;
end;
end.
Troppo complesso per le mie conoscenze di Lazarus; allora mi sono rivolto alla stampa tramite Printer; ora però non capisco proprio il problema: ho provato ad utilizzare modificandolo questo codice che funziona perfettamente:
unit Unit1;
{$mode objfpc}{$H+}
interface
uses
Classes, SysUtils, FileUtil, Forms, Controls, Graphics, Dialogs, Printers,
StdCtrls;
type
{ TForm1 }
TForm1 = class(TForm)
PrintBtn: TButton;
procedure PrintBtnClick(Sender: TObject);
private
{ private declarations }
public
{ public declarations }
end;
var
Form1: TForm1;
implementation
{$R *.lfm}
{ TForm1 }
procedure TForm1.PrintBtnClick(Sender: TObject);
const
LEFTMARGIN = 100;
HEADLINE = 'I Printed My Very First Text On ';
var
YPos, LineHeight, VerticalMargin: Integer;
SuccessString: String;
i:integer;
arrstr: array[1..10] of string;
begin
arrstr[1]:='UNO'; arrstr[2]:='DUE'; arrstr[3]:='TRE'; arrstr[4]:='QUATTRO'; arrstr[5]:='CINQUE';
arrstr[6]:='SEI'; arrstr[7]:='SETTE'; arrstr[8]:='OTTO'; arrstr[9]:='NOVE'; arrstr[10]:='DIECI';
with Printer do
try
BeginDoc;
Canvas.Font.Name := 'Verdana';
Canvas.Font.Size := 8;
Canvas.Font.Color := clBlack;
LineHeight := Round(1.2 * Abs(Canvas.TextHeight('I')));
VerticalMargin := 4 * LineHeight;
// There we go
YPos := VerticalMargin;
Canvas.TextOut(Leftmargin,YPos,'Data Fattura Numero Fattura Protocollo Totale Fattura');
for i:= 1 to 10 do begin
YPos:=YPos+150;
Canvas.TextOut(LEFTMARGIN, YPos, arrstr[i]);
end;
finally
EndDoc;
end;
end;
end.
ebbene prendo la procedura e la trasporto all'interno di altro applicativo: risultato
Il progetto .... ha sollevato un'eccezione di classe External:SIGSEGV in file Printers.pas at line 517
//Raise error if Printer.Printing is not Value
procedure TPrinter.CheckPrinting(Value: Boolean);
begin
if Printing<>Value then
begin
if Value then
raise EPrinter.Create('Printer is not printing')
else
raise Eprinter.Create('Printer is printing');
end;
end;
e questo il pezzo di progetto
unit UMenustampe;
{$mode objfpc}{$H+}
interface
uses
Classes, SysUtils, FileUtil, Forms, Controls, Graphics, Dialogs, Printers,StdCtrls;
const
percorso='c:\GestCesp\Marcheluzzo\2014';
nomefileces ='cespiti.dat';
nomefilecate ='specie.dat';
intestazione='Libro Cespiti anno 2014 Marcheluzzo srl';
type
CategoriaCespite = record
Gruppo:integer;
DescGruppo:string[100];
NumSpecie:string [10];
Desspecie:string [200];
CodTipo:string[10];
DescTipo:string[100];
AliqTipo:real;
end;
Cespite = record
NumCes:integer;
DataFatt:string [10];
NumFatt:string[20];
Prot:integer;
Fornit:string [50];
Descrizione:string [60];
Costo:real;
Fondo:real;
Residuo:real;
CodCat: CategoriaCespite;
PercAmm:real;
PercDet:real;
DataVend:string[10];
ValVend:real;
Plusv:real;
end;
{ TTfMenuStampe }
TTfMenuStampe = class(TForm)
BtGlobale: TButton;
Button2: TButton;
procedure BtGlobaleClick(Sender: TObject);
private
{ private declarations }
public
{ public declarations }
end;
var
TfMenuStampe: TTfMenuStampe;
arrces:array [1..500] of Cespite;
arrcate:array[1..500] of CategoriaCespite;
ces:cespite;
cate:CategoriaCespite;
FileCes:file of cespite;
FileCate: file of CategoriaCespite;
idx,idxc:integer;
xmar,ypos,LineHeight,verticalmargin,leftmargin:integer;
primades,secondades:string;
implementation
{$R *.lfm}
{ TTfMenuStampe }
procedure AzzeraCespite;
begin
ces.NumCes:=0;ces.DataFatt:='';ces.NumFatt:='';ces.Prot:=0;ces.Fornit:='';ces.Descrizione:='';
ces.Costo:=0;ces.Fondo:=0;ces.Residuo:=0;ces.CodCat:=cate;ces.PercAmm:=0;ces.PercDet:=0;
ces.DataVend:='';ces.ValVend:=0;ces.Plusv:=0;
end;
procedure AzzeraCategoria;
begin
cate.Gruppo:=0;cate.DescGruppo:='';cate.NumSpecie:='';
cate.Desspecie:='';cate.CodTipo:='';cate.DescTipo:='';
cate.AliqTipo:=0;
end;
procedure LeggiCategoria;
var i:integer;
begin
for i:=1 to 500 do arrcate[i]:=cate;
chdir (percorso);
assignFile (FileCate,nomefilecate);
reset (FileCate);
idxc:=0;
while not eof (FileCate) do begin
idxc:=idxc+1;
read (FileCate,arrcate[idxc]);
end;
CloseFile(FileCate);
end;
procedure LeggiCespiti;
var i:integer;
begin
for i:=1 to 500 do arrces[i]:=ces;
chdir (percorso);
assignFile (FileCes,nomefileces);
reset(FileCes);
idx:=0;
while not eof (FileCes) do begin
idx:=idx+1;
read(FileCes,arrces[idx]);
end;
CloseFile(FileCes);
end;
procedure Stampaintestazione;
const
LEFTMARGIN = 100;
HEADLINE = 'I Printed My Very First Text On ';
var
YPos, LineHeight, VerticalMargin: Integer;
SuccessString: String;
i:integer;
arrstr: array[1..10] of string;
begin
arrstr[1]:='UNO'; arrstr[2]:='DUE'; arrstr[3]:='TRE'; arrstr[4]:='QUATTRO'; arrstr[5]:='CINQUE';
arrstr[6]:='SEI'; arrstr[7]:='SETTE'; arrstr[8]:='OTTO'; arrstr[9]:='NOVE'; arrstr[10]:='DIECI';
with Printer do
try
BeginDoc;
Canvas.Font.Name := 'Verdana';
Canvas.Font.Size := 8;
Canvas.Font.Color := clBlack;
LineHeight := Round(1.2 * Abs(Canvas.TextHeight('I')));
VerticalMargin := 4 * LineHeight;
// There we go
YPos := VerticalMargin;
Canvas.TextOut(Leftmargin,YPos,intestazione);
for i:= 1 to 10 do begin
YPos:=YPos+150;
Canvas.TextOut(LEFTMARGIN, YPos, arrstr[i]);
end;
finally
EndDoc;
end;
end;
procedure TTfMenuStampe.BtGlobaleClick(Sender: TObject);
begin
AzzeraCategoria;AzzeraCespite;LeggiCategoria;LeggiCespiti;
Stampaintestazione;
end;
end.
perchè non va? è uguale :'( :'( :'(