LazReport, added sample for OnUserFunction to editor project

git-svn-id: trunk@27441 -
This commit is contained in:
jesus 2010-09-22 21:18:05 +00:00
parent 5e315771f3
commit f44d2bc88f
3 changed files with 102 additions and 34 deletions

View File

@ -7,6 +7,7 @@ object frmMain: TfrmMain
Caption = 'LazReport Test Suite' Caption = 'LazReport Test Suite'
ClientHeight = 522 ClientHeight = 522
ClientWidth = 828 ClientWidth = 828
Font.Name = 'Sans'
Menu = MainMenu1 Menu = MainMenu1
OnCreate = frmMainCreate OnCreate = frmMainCreate
ShowHint = True ShowHint = True
@ -15,9 +16,9 @@ object frmMain: TfrmMain
AnchorSideLeft.Control = Owner AnchorSideLeft.Control = Owner
AnchorSideBottom.Control = grid AnchorSideBottom.Control = grid
Left = 6 Left = 6
Height = 16 Height = 18
Top = 103 Top = 103
Width = 35 Width = 38
Anchors = [akLeft, akBottom] Anchors = [akLeft, akBottom]
BorderSpacing.Around = 6 BorderSpacing.Around = 6
Caption = 'Index' Caption = 'Index'
@ -27,10 +28,10 @@ object frmMain: TfrmMain
AnchorSideRight.Control = Owner AnchorSideRight.Control = Owner
AnchorSideRight.Side = asrBottom AnchorSideRight.Side = asrBottom
AnchorSideBottom.Control = grid AnchorSideBottom.Control = grid
Left = 752 Left = 745
Height = 16 Height = 18
Top = 103 Top = 103
Width = 70 Width = 77
Anchors = [akRight, akBottom] Anchors = [akRight, akBottom]
BorderSpacing.Around = 6 BorderSpacing.Around = 6
Caption = 'Expression' Caption = 'Expression'
@ -54,10 +55,10 @@ object frmMain: TfrmMain
AnchorSideTop.Side = asrBottom AnchorSideTop.Side = asrBottom
AnchorSideRight.Control = lblExpr AnchorSideRight.Control = lblExpr
AnchorSideBottom.Control = grid AnchorSideBottom.Control = grid
Left = 47 Left = 50
Height = 29 Height = 31
Top = 90 Top = 90
Width = 699 Width = 689
Anchors = [akTop, akLeft, akRight] Anchors = [akTop, akLeft, akRight]
BorderSpacing.Around = 6 BorderSpacing.Around = 6
ItemHeight = 0 ItemHeight = 0
@ -71,14 +72,15 @@ object frmMain: TfrmMain
AnchorSideRight.Control = grid AnchorSideRight.Control = grid
AnchorSideBottom.Control = sbar AnchorSideBottom.Control = sbar
Left = 0 Left = 0
Height = 380 Height = 378
Top = 125 Top = 127
Width = 204 Width = 204
Anchors = [akTop, akLeft, akBottom] Anchors = [akTop, akLeft, akBottom]
Color = clMoneyGreen Color = clMoneyGreen
Columns = <> Columns = <>
DataSource = srcMaster DataSource = srcMaster
TabOrder = 3 TabOrder = 3
TitleFont.Name = 'Sans'
Visible = False Visible = False
end end
object grid: TDBGrid object grid: TDBGrid
@ -89,15 +91,18 @@ object frmMain: TfrmMain
AnchorSideRight.Side = asrBottom AnchorSideRight.Side = asrBottom
AnchorSideBottom.Control = sbar AnchorSideBottom.Control = sbar
Left = 0 Left = 0
Height = 380 Height = 378
Top = 125 Top = 127
Width = 828 Width = 828
Anchors = [akTop, akLeft, akRight, akBottom] Anchors = [akTop, akLeft, akRight, akBottom]
Color = clWhite Color = clWhite
Columns = <> Columns = <>
DataSource = srcDetail DataSource = srcDetail
Font.Name = 'Sans'
Options = [dgEditing, dgTitles, dgIndicator, dgColumnResize, dgColLines, dgRowLines, dgTabs, dgAlwaysShowSelection, dgConfirmDelete, dgCancelOnExit] Options = [dgEditing, dgTitles, dgIndicator, dgColumnResize, dgColLines, dgRowLines, dgTabs, dgAlwaysShowSelection, dgConfirmDelete, dgCancelOnExit]
ParentFont = False
TabOrder = 0 TabOrder = 0
TitleFont.Name = 'Sans'
OnTitleClick = gridTitleClick OnTitleClick = gridTitleClick
end end
object Panel1: TPanel object Panel1: TPanel
@ -118,47 +123,47 @@ object frmMain: TfrmMain
Left = 6 Left = 6
Height = 33 Height = 33
Top = 6 Top = 6
Width = 169 Width = 170
Action = accNewReport Action = accNewReport
AutoSize = True AutoSize = True
BorderSpacing.Around = 6 BorderSpacing.Around = 6
TabOrder = 0 TabOrder = 0
end end
object btnOpenReport: TButton object btnOpenReport: TButton
Left = 181 Left = 182
Height = 33 Height = 33
Top = 6 Top = 6
Width = 146 Width = 147
Action = accOpenReport Action = accOpenReport
AutoSize = True AutoSize = True
BorderSpacing.Around = 6 BorderSpacing.Around = 6
TabOrder = 2 TabOrder = 2
end end
object btnEditReport: TButton object btnEditReport: TButton
Left = 333 Left = 335
Height = 33 Height = 33
Top = 6 Top = 6
Width = 136 Width = 135
Action = accEditReport Action = accEditReport
AutoSize = True AutoSize = True
BorderSpacing.Around = 6 BorderSpacing.Around = 6
TabOrder = 3 TabOrder = 3
end end
object btnPreviewReport: TButton object btnPreviewReport: TButton
Left = 475 Left = 476
Height = 33 Height = 33
Top = 6 Top = 6
Width = 160 Width = 162
Action = accPreviewReport Action = accPreviewReport
AutoSize = True AutoSize = True
BorderSpacing.Around = 6 BorderSpacing.Around = 6
TabOrder = 4 TabOrder = 4
end end
object btnPrintReport: TButton object btnPrintReport: TButton
Left = 641 Left = 644
Height = 33 Height = 33
Top = 6 Top = 6
Width = 181 Width = 178
Action = accPrintReport Action = accPrintReport
AutoSize = True AutoSize = True
BorderSpacing.Around = 6 BorderSpacing.Around = 6
@ -168,7 +173,7 @@ object frmMain: TfrmMain
Left = 6 Left = 6
Height = 33 Height = 33
Top = 45 Top = 45
Width = 169 Width = 170
Action = accCustomPreview Action = accCustomPreview
AutoSize = True AutoSize = True
BorderSpacing.Around = 6 BorderSpacing.Around = 6
@ -176,10 +181,10 @@ object frmMain: TfrmMain
end end
object btnPrintGrid: TButton object btnPrintGrid: TButton
AnchorSideRight.Side = asrBottom AnchorSideRight.Side = asrBottom
Left = 181 Left = 182
Height = 33 Height = 33
Top = 45 Top = 45
Width = 146 Width = 147
Action = accPrintGrid Action = accPrintGrid
AutoSize = True AutoSize = True
BorderSpacing.Around = 6 BorderSpacing.Around = 6
@ -187,10 +192,10 @@ object frmMain: TfrmMain
end end
object btnComposite: TButton object btnComposite: TButton
AnchorSideTop.Side = asrBottom AnchorSideTop.Side = asrBottom
Left = 333 Left = 335
Height = 33 Height = 33
Top = 45 Top = 45
Width = 136 Width = 135
Action = accComposite Action = accComposite
AutoSize = True AutoSize = True
BorderSpacing.Around = 6 BorderSpacing.Around = 6
@ -199,20 +204,20 @@ object frmMain: TfrmMain
object btnImageList: TButton object btnImageList: TButton
AnchorSideTop.Side = asrBottom AnchorSideTop.Side = asrBottom
AnchorSideRight.Side = asrBottom AnchorSideRight.Side = asrBottom
Left = 475 Left = 476
Height = 33 Height = 33
Top = 45 Top = 45
Width = 160 Width = 162
Action = accThumbnails Action = accThumbnails
AutoSize = True AutoSize = True
BorderSpacing.Around = 6 BorderSpacing.Around = 6
TabOrder = 7 TabOrder = 7
end end
object btnMasterDetail: TToggleBox object btnMasterDetail: TToggleBox
Left = 641 Left = 644
Height = 33 Height = 33
Top = 45 Top = 45
Width = 181 Width = 178
AutoSize = True AutoSize = True
BorderSpacing.Around = 6 BorderSpacing.Around = 6
Caption = 'Master-Detail Test' Caption = 'Master-Detail Test'
@ -223,12 +228,13 @@ object frmMain: TfrmMain
object TheReport: TfrReport object TheReport: TfrReport
Dataset = frDbDetail Dataset = frDbDetail
InitialZoom = pzDefault InitialZoom = pzDefault
Options = [] Options = [roIgnoreFieldNotFound]
PreviewButtons = [pbZoom, pbLoad, pbSave, pbPrint, pbFind, pbHelp, pbExit] PreviewButtons = [pbZoom, pbLoad, pbSave, pbPrint, pbFind, pbHelp, pbExit]
DataType = dtDataSet DataType = dtDataSet
OnBeginDoc = TheReportBeginDoc OnBeginDoc = TheReportBeginDoc
OnGetValue = TheReportGetValue OnGetValue = TheReportGetValue
OnEnterRect = TheReportEnterRect OnEnterRect = TheReportEnterRect
OnUserFunction = TheReportUserFunction
OnExportFilterSetup = TheReportExportFilterSetup OnExportFilterSetup = TheReportExportFilterSetup
left = 40 left = 40
top = 192 top = 192
@ -397,6 +403,8 @@ object frmMain: TfrmMain
object PrintGrid: TFrPrintGrid object PrintGrid: TFrPrintGrid
DBGrid = grid DBGrid = grid
Orientation = poLandscape Orientation = poLandscape
Font.Name = 'Sans'
TitleFont.Name = 'Sans'
Caption = 'Grid' Caption = 'Grid'
ShowCaption = True ShowCaption = True
left = 352 left = 352

View File

@ -26,11 +26,11 @@ unit maincalleditor;
interface interface
uses uses
Classes, SysUtils, FileUtil, LResources, Forms, Controls, Graphics, Dialogs, Classes, SysUtils, Variants, FileUtil, LResources, Forms, Controls, Graphics, Dialogs,
Buttons, StdCtrls, LR_Const, LR_Class, LR_Desgn, Dbf, DB, DBGrids, LR_DBSet, Buttons, StdCtrls, LR_Const, LR_Class, LR_Desgn, Dbf, DB, DBGrids, LR_DBSet,
LR_PGrid, Menus, ComCtrls, ActnList, Lr_e_txt, Lr_e_htm, LR_E_CSV, LR_DSet, LR_PGrid, Menus, ComCtrls, ActnList, Lr_e_txt, Lr_e_htm, LR_E_CSV, LR_DSet,
LR_BarC, LR_RRect, LR_Shape, LR_ChBox, lr_e_pdf, lconvencoding, lr_e_gen, LR_BarC, LR_RRect, LR_Shape, LR_ChBox, lr_e_pdf, lconvencoding, lr_e_gen,
lr_utils, LCLProc, ExtCtrls, custompreview; lr_utils, LCLProc, ExtCtrls, custompreview, LR_Pars;
type type
@ -140,6 +140,8 @@ type
procedure TheReportEnterRect(Memo: TStringList; View: TfrView); procedure TheReportEnterRect(Memo: TStringList; View: TfrView);
procedure TheReportExportFilterSetup(Sender: TfrExportFilter); procedure TheReportExportFilterSetup(Sender: TfrExportFilter);
procedure TheReportGetValue(const ParName: String; var ParValue: Variant); procedure TheReportGetValue(const ParName: String; var ParValue: Variant);
procedure TheReportUserFunction(const AName: String; p1, p2, p3: Variant;
var Val: Variant);
private private
{ private declarations } { private declarations }
FImageList: TStringList; FImageList: TStringList;
@ -485,6 +487,21 @@ begin
end; end;
end; end;
procedure TfrmMain.TheReportUserFunction(const AName: String; p1, p2,
p3: Variant; var Val: Variant);
var
v: variant;
b: boolean;
begin
if AName='STOCKFLAG' then begin
v := frParser.Calc(P1);
if VarIsNull(V) or not boolean(v) then
Val := ':('
else
Val:= ':)';
end;
end;
procedure TfrmMain.SetIndex(const aIndexName: string); procedure TfrmMain.SetIndex(const aIndexName: string);
begin begin
Detail.IndexName := aIndexName; Detail.IndexName := aIndexName;

View File

@ -35,7 +35,7 @@
<ColCount Value="1"/> <ColCount Value="1"/>
<ColGap Value="0"/> <ColGap Value="0"/>
<LayoutOrder Value="loColumns"/> <LayoutOrder Value="loColumns"/>
<ObjectCount Value="6"/> <ObjectCount Value="7"/>
<Object1> <Object1>
<Name Value="ReportTitle1"/> <Name Value="ReportTitle1"/>
<ClassName Value="TfrBandView"/> <ClassName Value="TfrBandView"/>
@ -248,6 +248,49 @@
<Layout Value="tlTop"/> <Layout Value="tlTop"/>
<Angle Value="0"/> <Angle Value="0"/>
</Object6> </Object6>
<Object7>
<Name Value="Memo5"/>
<ClassName Value="TfrMemoView"/>
<Visible Value="1"/>
<Typ Value="gtMemo"/>
<StreamMode Value="0"/>
<Size>
<Left Value="624"/>
<Top Value="128"/>
<Width Value="96"/>
<Height Value="18"/>
</Size>
<Flags Value="3"/>
<FillColor Value="clNone"/>
<Frames>
<FrameColor Value="clBlack"/>
<FrameStyle Value="frsSolid"/>
<FrameWidth Value="1"/>
<FrameBorders Value=""/>
</Frames>
<Data>
<Format Value="556"/>
<FormatStr Value=""/>
<Memo Value="[StockFlag([Detail.&quot;IN_STOCK&quot;])]&#xA;"/>
<Script Value=""/>
</Data>
<Font>
<Name Value="helvetica [urw]"/>
<Size Value="10"/>
<Color Value="clBlack"/>
<Charset Value="0"/>
<Style Value=""/>
</Font>
<Highlight>
<FontStyle Value="2"/>
<FontColor Value="clBlack"/>
<FillColor Value="clWhite"/>
<HighlightStr Value=""/>
</Highlight>
<Alignment Value="taLeftJustify"/>
<Layout Value="tlTop"/>
<Angle Value="0"/>
</Object7>
</Page1> </Page1>
<FVal> <FVal>
<Count Value="0"/> <Count Value="0"/>