Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

How To Print the StringGrid?

330 views
Skip to first unread message

Haizhou Tang

unread,
Jan 12, 1999, 3:00:00 AM1/12/99
to
Hi,
Who can help me to print out the content of the StringGrid?

Tom


Barry Wood

unread,
Jan 12, 1999, 3:00:00 AM1/12/99
to
I just the same problem, but I use Ace Reporter and the boss there
(Steve Tyrakowski) sent me some code which works really very well.
Doesn't answer your question I'm afraid, but I'm chuffed I have a 3rd
party product with such good support!

Barry Wood

Michael Glatz

unread,
Jan 12, 1999, 3:00:00 AM1/12/99
to
What I did was to create a table (paradox) that stored the data from the
string grid (even the headers) and then used QuickReport to do the printout
on the table.

--
Michael Glatz
mgl...@caiso.com
Haizhou Tang wrote in message <369B6498...@homeway.com.cn>...

Peter Below

unread,
Jan 12, 1999, 3:00:00 AM1/12/99
to
In article <369B6498...@homeway.com.cn>, Haizhou Tang
wrote:

> Who can help me to print out the content of the StringGrid?
>
Manual work is required here <g>. Here is a method ripped from
on of my applications, it should show you the general principle
even if you cannot compile it as is since there are part
missing. This was a "quick hack" project and is thus severely
undercommented. Of course the thing is still in use three years
after the "use by" data <g>.

Procedure TACDListerMain.PrintTable;
Var
margins: TRect;
spacing: Integer;
Cols: TList;
Dlg: TPrintProgressDlg;

Procedure SetColumnWidth;
Var
i, k, w: Integer;
Begin
Printer.Canvas.Font.Style := [ fsBold ];
For i := 0 To Pred( Grid.ColCount ) Do
Cols.Add( Pointer( Printer.Canvas.TextWidth( Grid.Cells[
i,0 ] )));

Printer.Canvas.Font.Style := [];
For i := 1 To Pred( Grid.RowCount ) Do
For k := 0 To Pred( Grid.ColCount ) Do Begin
w:= Printer.Canvas.TextWidth( Grid.Cells[ k, i ] );
If w > Integer( Cols[ k ] ) Then
Cols[ k ] := Pointer( w );
End; { For }

w := 2 * Printer.Canvas.Font.PixelsPerInch div 3;
margins :=
Rect( w, w, Printer.PageWidth-w, Printer.PageHeight - w
);
spacing := Printer.Canvas.Font.PixelsPerInch div 10;

w := 0;
For i := 0 To Pred(cols.Count) Do
w := w + Integer( cols[ i ] ) + spacing;
w := w - spacing;
If w > (margins.right-margins.left ) Then Begin
w := w - (margins.right-margins.left );
cols[ cols.Count-2 ] :=
Pointer( Integer( cols[ cols.Count-2 ] ) - w );
End; { If }

w:= 0;
For i := 0 To Pred(cols.Count) Do
w := w + Integer( cols[ i ] ) + spacing;
margins.right := w - spacing + margins.left;
End; { SetColumnWidth }

Procedure DoPrint;
Var
i: Integer;
y: Integer;
Procedure DoLine(lineno: Integer);
Var
x, n: Integer;
r: TRect;
th: Integer;
Begin
If Length(Grid.Cells[0,lineno]) = 0 Then Exit;

x:= margins.left;
With Printer.Canvas Do Begin
th := TextHeight( 'Äy' );
For n := 0 To Pred( Cols.Count ) Do Begin
r := Rect( 0, 0, Integer(Cols[ n ]), th);
OffsetRect( r, x, y );
TextRect( r, x, y, Grid.Cells[ n, lineno ] );
x := r.right + spacing;
End; { For }
End; { With }
y := y + th;
End; { DoLine }
Procedure DoHeader;
Begin
y:= margins.top;
With Printer.Canvas Do Begin
Font.Style := [ fsBold ];
DoLine( 0 );
Pen.Width := Font.PixelsPerInch div 72;
Pen.Color := clBlack;
MoveTo( margins.left, y );
LineTo( margins.right, y );
Inc( y, 2 * Pen.Width );
Font.Style := [ ];
End; { With }
End; { DoHeader }
Begin
y:= 0;
For i := 1 To Pred( Grid.RowCount ) Do Begin
Dlg.Progress( i );
Application.ProcessMessages;
If FPrintAborted Then Exit;

If y = 0 Then
DoHeader;
DoLine( i );
If y >= margins.bottom Then Begin
Printer.NewPage;
y:= 0;
End; { If }
End; { For }
End; { DoPrint }

Begin
FPrintAborted := False;
Dlg := TPrintProgressDlg.Create( Application );
With Dlg Do
try
OnAbort := PrintAborted;
Display( cPrintPreparation );
SetProgressRange( 0, Grid.RowCount );
Show;
Application.ProcessMessages;
If not Assigned( FPrintSet ) Then
FPrintSet := TPrintSet.Create( Self );
FPrintSet.Orientation := dmorient_Landscape;

Application.ProcessMessages;
Printer.BeginDoc;
Cols:= Nil;
try
Cols:= TLIst.Create;
Printer.Canvas.Font.Assign( Grid.Font );
{$IFNDEF WIN32}
SetPixelsPerInch;
{$ENDIF}
SetColumnWidth;
Display( cPrintProceeding );
Application.ProcessMessages;
DoPrint;
finally
Cols.Free;
If FPrintAborted Then
{$IFDEF WIN32}
Printer.Abort
{$ELSE}
AbortDoc( Printer.Canvas.Handle );
{$ENDIF}
Else
Printer.EndDoc;
end;
finally
Close;
End; { With }
End; { TACDListerMain.PrintTable }

Peter Below (TeamB) 10011...@compuserve.com)
No e-mail responses, please, unless explicitely requested!


Haizhou Tang

unread,
Jan 13, 1999, 3:00:00 AM1/13/99
to Michael Glatz
Thank you for your reply.
However if I send this program to others through the Internet, I can not send
the
BDE and can not make others use my application directly.
It's something difficult?

Tom

Michael Glatz 写到:

> What I did was to create a table (paradox) that stored the data from the
> string grid (even the headers) and then used QuickReport to do the printout
> on the table.
>
> --
> Michael Glatz
> mgl...@caiso.com
> Haizhou Tang wrote in message <369B6498...@homeway.com.cn>...
> >Hi,

> >Who can help me to print out the content of the StringGrid?
> >

> >Tom
> >


Bruno Fierens

unread,
Jan 14, 1999, 3:00:00 AM1/14/99
to
>Who can help me to print out the content of the StringGrid?


Have a look at TAdvStringGrid,
it has built in printing among lots of other features,

It's available at : http://users.skynet.be/delphi

Kr,
Bruno

0 new messages