jvcllaz: Fix stack overflow in JvTimeFrameWork demo due to TJvTFDaysPrinter.

git-svn-id: https://svn.code.sf.net/p/lazarus-ccr/svn@7099 8e941d3f-bd1b-0410-a28a-d453659cc2b4
This commit is contained in:
wp_xxyyzz
2019-08-07 21:17:30 +00:00
parent 7e2bd8e653
commit 41e17a30f3
3 changed files with 103 additions and 27 deletions

View File

@ -1123,7 +1123,7 @@ object MainForm: TMainForm
LineSpacing = 2 LineSpacing = 2
ShowStartEnd = False ShowStartEnd = False
left = 304 left = 304
top = 224 top = 200
end end
object dbUTF: TSQLite3Connection object dbUTF: TSQLite3Connection
Connected = False Connected = False
@ -1497,4 +1497,56 @@ object MainForm: TMainForm
36348834EDAD6AFF03880DBFF8 36348834EDAD6AFF03880DBFF8
} }
end end
object JvTFDaysPrinter1: TJvTFDaysPrinter
ScheduleManager = utfScheduleManager1
PageLayout.FooterHeight = 0
PageLayout.HeaderHeight = 0
PageLayout.MarginLeft = 25
PageLayout.MarginTop = 17
PageLayout.MarginRight = 25
PageLayout.MarginBottom = 63
PageLayout.ColsPerPage = 0
PageLayout.RowsPerPage = 0
PageLayout.AlwaysShowColHdr = False
PageLayout.AlwaysShowRowHdr = False
OnPrintProgress = JvTFDaysPrinter1PrintProgress
OnAssembleProgress = JvTFDaysPrinter1AssembleProgress
Title = 'SIMPLDaysPrinter Demo'
ApptAttr.Color = clLime
ApptAttr.ParentFont = False
ApptBuffer = 0
ColHdrHeight = 0
Color = clBlack
Cols = <>
ColTitleStyle = ctsSingleClip
DateFormat = 'ddddd'
FancyRowHdrAttr.Hr2400 = False
FancyRowHdrAttr.MajorFont.Height = -19
FormattedDesc = False
Granularity = 1
GridLineColor = clBlack
GroupHdrAttr.Font.Color = clWindowText
GroupHdrAttr.ParentFont = False
GroupHdrAttr.FrameColor = clBlack
Grouping = grNone
HdrAttr.Font.Color = clWindowText
HdrAttr.ParentFont = False
HdrAttr.FrameColor = clBlack
MinColWidth = 5
MinRowHeight = 1
PrimeTime.StartTime = 0.333333333333333
PrimeTime.EndTime = 0.708333333333333
PrimeTime.Color = clYellow
RowHdrType = rhGrid
RowHdrWidth = 0
RowHeight = 0
ShowPics = False
ShowText = False
TimeFormat = 't'
OnApptProgress = JvTFDaysPrinter1ApptProgress
GridStartTime = 0
GridEndTime = 0
left = 304
top = 259
end
end end

View File

@ -43,6 +43,7 @@ type
TMainForm = class(TForm) TMainForm = class(TForm)
ImageList: TImageList; ImageList: TImageList;
JvTFDaysPrinter1: TJvTFDaysPrinter;
Label1: TLabel; Label1: TLabel;
Label2: TLabel; Label2: TLabel;
Panel2: TPanel; Panel2: TPanel;
@ -576,26 +577,24 @@ end;
procedure TMainForm.PrintButtonClick(Sender: TObject); procedure TMainForm.PrintButtonClick(Sender: TObject);
begin begin
(******************** wp: deactivated due to stack overflow ************ with JvTFDaysPrinter1 do
With JvTFDaysPrinter1 do begin
Begin // "Copy" the display properties from the JvTFDays control
// "Copy" the display properties from the JvTFDays control SetProperties(JvTFDays1);
SetProperties(JvTFDays1); // Set gridline color to black for sharp display on printed page
// Set gridline color to black for sharp display on printed page GridLineColor := clBlack;
GridLineColor := clBlack; // print 48 rows on each page
// print 48 rows on each page PageLayout.RowsPerPage := 48;
PageLayout.RowsPerPage := 48; // fit all the columns onto one page wide
// fit all the columns onto one page wide PageLayout.ColsPerPage := 0;
PageLayout.ColsPerPage := 0; // "Copy" the schedules from the JvTFDays control
// "Copy" the schedules from the JvTFDays control Cols.Assign(JvTFDays1.Cols);
Cols.Assign(JvTFDays1.Cols); PrintProgress.Show;
PrintProgress.Show; Application.ProcessMessages;
Application.ProcessMessages; // print the document
// print the document PrintDirect;
PrintDirect; PrintProgress.Close;
PrintProgress.Close; end;
End;
************************)
end; end;
procedure TMainForm.JvTFDaysPrinter1ApptProgress(Sender: TObject; procedure TMainForm.JvTFDaysPrinter1ApptProgress(Sender: TObject;

View File

@ -32,7 +32,7 @@ interface
uses uses
LCLIntf, LCLType, LCLIntf, LCLType,
Classes, SysUtils, Controls, //Windows, Messages, Classes, SysUtils, Controls,
Graphics, ImgList, ExtCtrls, Printers, Forms, Graphics, ImgList, ExtCtrls, Printers, Forms,
//JvComponentBase, //JvComponentBase,
JvComponent, JvTypes, JvTFUtils; JvComponent, JvTypes, JvTFUtils;
@ -4339,6 +4339,7 @@ const
var var
PPI: Integer; PPI: Integer;
begin begin
(**************** DONE
PPI := 300; // wp -- just a workaround for next commented lines... PPI := 300; // wp -- just a workaround for next commented lines...
{ wp --- to do { wp --- to do
if Horizontal then if Horizontal then
@ -4346,6 +4347,11 @@ begin
else else
PPI := Windows.GetDeviceCaps(Printer.Handle, LOGPIXELSY); PPI := Windows.GetDeviceCaps(Printer.Handle, LOGPIXELSY);
} }
******************)
if Horizontal then
PPI := Printer.XDPI
else
PPI := Printer.YDPI;
if (FromMeasure = pmPixels) and (ToMeasure = pmInches) then if (FromMeasure = pmPixels) and (ToMeasure = pmInches) then
Result := round(Value / PPI * 100) Result := round(Value / PPI * 100)
else else
@ -4483,9 +4489,10 @@ function TJvTFPrinter.GetBodyHeight: Integer; // always in pixels
var var
PhysHeight, TopMarginPels, BottomMarginPels, HeaderPels, FooterPels: Integer; PhysHeight, TopMarginPels, BottomMarginPels, HeaderPels, FooterPels: Integer;
begin begin
{ wp --- to do { wp --- to do **************** DONE ***************
PhysHeight := Windows.GetDeviceCaps(Printer.Handle, PHYSICALHEIGHT); PhysHeight := Windows.GetDeviceCaps(Printer.Handle, PHYSICALHEIGHT);
} }
PhysHeight := Printer.PaperSize.Height;
TopMarginPels := ConvertMeasure(PageLayout.MarginTop, Measure, pmPixels, False); TopMarginPels := ConvertMeasure(PageLayout.MarginTop, Measure, pmPixels, False);
BottomMarginPels := ConvertMeasure(PageLayout.MarginBottom, Measure, pmPixels, False); BottomMarginPels := ConvertMeasure(PageLayout.MarginBottom, Measure, pmPixels, False);
HeaderPels := ConvertMeasure(PageLayout.HeaderHeight, Measure, pmPixels, False); HeaderPels := ConvertMeasure(PageLayout.HeaderHeight, Measure, pmPixels, False);
@ -4510,9 +4517,10 @@ function TJvTFPrinter.GetBodyWidth: Integer; // always in pixels
var var
PhysWidth, LeftMarginPels, RightMarginPels: Integer; PhysWidth, LeftMarginPels, RightMarginPels: Integer;
begin begin
{ wp --- to do { wp --- to do **************** DONE *****************
PhysWidth := Windows.GetDeviceCaps(Printer.Handle, PHYSICALWIDTH); PhysWidth := Windows.GetDeviceCaps(Printer.Handle, PHYSICALWIDTH);
} }
PhysWidth := Printer.PaperSize.Width;
LeftMarginPels := ConvertMeasure(PageLayout.MarginLeft, Measure, pmPixels, True); LeftMarginPels := ConvertMeasure(PageLayout.MarginLeft, Measure, pmPixels, True);
RightMarginPels := ConvertMeasure(PageLayout.MarginRight, Measure, pmPixels, True); RightMarginPels := ConvertMeasure(PageLayout.MarginRight, Measure, pmPixels, True);
@ -4589,12 +4597,16 @@ function TJvTFPrinter.GetUnprintable: TJvTFMargins;
var var
LeftMarg, TopMarg, WidthPaper, HeightPaper, WidthPrintable, HeightPrintable: Integer; LeftMarg, TopMarg, WidthPaper, HeightPaper, WidthPrintable, HeightPrintable: Integer;
begin begin
{ wp --- to do { wp --- to do ----------- DONE ----------------
LeftMarg := Windows.GetDeviceCaps(Printer.Handle, PHYSICALOFFSETX); LeftMarg := Windows.GetDeviceCaps(Printer.Handle, PHYSICALOFFSETX);
TopMarg := Windows.GetDeviceCaps(Printer.Handle, PHYSICALOFFSETY); TopMarg := Windows.GetDeviceCaps(Printer.Handle, PHYSICALOFFSETY);
WidthPaper := Windows.GetDeviceCaps(Printer.Handle, PHYSICALWIDTH); WidthPaper := Windows.GetDeviceCaps(Printer.Handle, PHYSICALWIDTH);
HeightPaper := Windows.GetDeviceCaps(Printer.Handle, PHYSICALHEIGHT); HeightPaper := Windows.GetDeviceCaps(Printer.Handle, PHYSICALHEIGHT);
} }
LeftMarg := Printer.PaperSize.PaperRect.WorkRect.Left;
TopMarg := Printer.PaperSize.PaperRect.WorkRect.Top;
WidthPaper := Printer.PaperSize.Width;
HeightPaper := Printer.PaperSize.Height;
WidthPrintable := Printer.PageWidth; WidthPrintable := Printer.PageWidth;
HeightPrintable := Printer.PageHeight; HeightPrintable := Printer.PageHeight;
@ -4749,13 +4761,18 @@ function TJvTFPrinter.PrinterToScreen(Value: Integer;
var var
ScreenPPI, PrinterPPI: Integer; ScreenPPI, PrinterPPI: Integer;
begin begin
{ wp --- to do { wp --- to do ************* DONE ************
ScreenPPI := Screen.PixelsPerInch; ScreenPPI := Screen.PixelsPerInch;
if Horizontal then if Horizontal then
PrinterPPI := Windows.GetDeviceCaps(Printer.Handle, LOGPIXELSX) PrinterPPI := Windows.GetDeviceCaps(Printer.Handle, LOGPIXELSX)
else else
PrinterPPI := Windows.GetDeviceCaps(Printer.Handle, LOGPIXELSY); PrinterPPI := Windows.GetDeviceCaps(Printer.Handle, LOGPIXELSY);
} }
ScreenPPI := Screen.PixelsPerInch;
if Horizontal then
PrinterPPI := Printer.XDPI
else
PrinterPPI := Printer.YDPI;
Result := Trunc(ScreenPPI / PrinterPPI * Value); Result := Trunc(ScreenPPI / PrinterPPI * Value);
end; end;
@ -4778,7 +4795,11 @@ var
ScreenPPI, PrinterPPI: Integer; ScreenPPI, PrinterPPI: Integer;
begin begin
ScreenPPI := Screen.PixelsPerInch; ScreenPPI := Screen.PixelsPerInch;
{ wp --- to do if Horizontal then
PrinterPPI := Printer.XDPI
else
PrinterPPI := Printer.YDPI;
{ wp --- to do *********** DONE ***********
if Horizontal then if Horizontal then
PrinterPPI := Windows.GetDeviceCaps(Printer.Handle, LOGPIXELSX) PrinterPPI := Windows.GetDeviceCaps(Printer.Handle, LOGPIXELSX)
else else
@ -4860,6 +4881,10 @@ begin
raise EJvTFPrinterError.CreateRes(@RsECouldNotCreateTJvTFPrinterPageLayou); raise EJvTFPrinterError.CreateRes(@RsECouldNotCreateTJvTFPrinterPageLayou);
FPrinter := aPrinter; FPrinter := aPrinter;
FMargins.Left := 25;
FMargins.Right := 25;
FMargins.Top := 17;
FMargins.Bottom := 63;
end; end;
procedure TJvTFPrinterPageLayout.Assign(Source: TPersistent); procedure TJvTFPrinterPageLayout.Assign(Source: TPersistent);