home *** CD-ROM | disk | FTP | other *** search
/ Chip 2003 January / Chip_2003-01_cd1.bin / zkuste / delphi / kolekce / d567 / FLEXCEL.ZIP / Demo / FlDemo / UFlDemo.pas < prev    next >
Encoding:
Pascal/Delphi Source File  |  2002-10-09  |  17.8 KB  |  589 lines

  1. unit UFlDemo;
  2.  
  3. interface
  4.  
  5. uses
  6.   Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
  7.   StdCtrls, ComCtrls, ExtCtrls, ActnList, ImgList, ToolWin, TemplateStore,
  8.   XLSAdapter, UExcelAdapter, OLEAdapter, UFlexCelImport, UFlexcelReport,
  9.   UReport, UFlDemoData, ShellApi, Grids, DBCtrls,
  10.   UFlDemoEdit, UWaitCursor, UExcelEdit, Menus, FileCtrl, UFlxMessages;
  11.  
  12. type
  13.   TMain = class(TForm)
  14.     ActionList: TActionList;
  15.     ActionClose: TAction;
  16.     ActionReport: TAction;
  17.     ActionUseOle: TAction;
  18.     ActionUseNative: TAction;
  19.     ActionHtml: TAction;
  20.     ActionProtect: TAction;
  21.     ActionViewTemplateExcel: TAction;
  22.     ActionUseTStore: TAction;
  23.     Panel1: TPanel;
  24.     Splitter1: TSplitter;
  25.     ListDemos: TTreeView;
  26.     Tabs: TPageControl;
  27.     TabSheet1: TTabSheet;
  28.     Panel2: TPanel;
  29.     TxtWelcome: TRichEdit;
  30.     TabSheet2: TTabSheet;
  31.     Panel3: TPanel;
  32.     Label3: TLabel;
  33.     TabSheet3: TTabSheet;
  34.     Panel4: TPanel;
  35.     Label2: TLabel;
  36.     TxtSimpleDemo: TRichEdit;
  37.     TabSheet4: TTabSheet;
  38.     Panel5: TPanel;
  39.     Label1: TLabel;
  40.     TxtVarArr: TRichEdit;
  41.     Panel6: TPanel;
  42.     Label4: TLabel;
  43.     TabSheet5: TTabSheet;
  44.     Panel7: TPanel;
  45.     Label5: TLabel;
  46.     TxtDbDemo: TRichEdit;
  47.     Panel8: TPanel;
  48.     Label6: TLabel;
  49.     DBLookupComboBox1: TDBLookupComboBox;
  50.     TabSheet6: TTabSheet;
  51.     Panel9: TPanel;
  52.     Label7: TLabel;
  53.     TxtMultMast: TRichEdit;
  54.     TabSheet7: TTabSheet;
  55.     Panel10: TPanel;
  56.     Label8: TLabel;
  57.     TxtSheets: TRichEdit;
  58.     TabSheet8: TTabSheet;
  59.     TabSheet9: TTabSheet;
  60.     TabSheet10: TTabSheet;
  61.     TabSheet11: TTabSheet;
  62.     TabSheet12: TTabSheet;
  63.     TabSheet13: TTabSheet;
  64.     ToolBar: TToolBar;
  65.     BtnUseNative: TToolButton;
  66.     BtnUseOle: TToolButton;
  67.     ToolButton5: TToolButton;
  68.     BtnHTML: TToolButton;
  69.     BtnProtect: TToolButton;
  70.     BtnUseTStore: TToolButton;
  71.     ToolButton2: TToolButton;
  72.     BtnReport: TToolButton;
  73.     BtnViewTemplate: TToolButton;
  74.     BtnClose: TToolButton;
  75.     StatusBar: TStatusBar;
  76.     Panel11: TPanel;
  77.     Label9: TLabel;
  78.     TxtFishFacts: TRichEdit;
  79.     PageControl1: TPageControl;
  80.     TabSheet15: TTabSheet;
  81.     TabSheet16: TTabSheet;
  82.     GridVarArray1: TStringGrid;
  83.     GridVarArray2: TStringGrid;
  84.     Panel12: TPanel;
  85.     Label10: TLabel;
  86.     TxtPivot: TRichEdit;
  87.     Panel13: TPanel;
  88.     Label11: TLabel;
  89.     TxtEvents: TRichEdit;
  90.     Panel14: TPanel;
  91.     Label12: TLabel;
  92.     TxtCustom: TRichEdit;
  93.     Label13: TLabel;
  94.     edSQL: TMemo;
  95.     Panel15: TPanel;
  96.     Label14: TLabel;
  97.     TxtReadFile: TRichEdit;
  98.     ToolButton1: TToolButton;
  99.     TabSheet17: TTabSheet;
  100.     Panel16: TPanel;
  101.     Label15: TLabel;
  102.     TxtCharts: TRichEdit;
  103.     Panel17: TPanel;
  104.     Label16: TLabel;
  105.     TxtImport: TRichEdit;
  106.     TxtReport: TRichEdit;
  107.     ActionPreview: TAction;
  108.     TabSheet14: TTabSheet;
  109.     Panel18: TPanel;
  110.     Label17: TLabel;
  111.     TxtImgDemo: TRichEdit;
  112.     Panel19: TPanel;
  113.     Label18: TLabel;
  114.     edMyImage: TEdit;
  115.     btnOpenMyImage: TButton;
  116.     PopViewTemplate: TPopupMenu;
  117.     VievwithExcel1: TMenuItem;
  118.     Openwithinternaleditor1: TMenuItem;
  119.     ActionViewTemplateInternal: TAction;
  120.     TabSheet18: TTabSheet;
  121.     TxtSideBySide: TRichEdit;
  122.     Label19: TLabel;
  123.     PopReport: TPopupMenu;
  124.     MenuItem1: TMenuItem;
  125.     MenuItem2: TMenuItem;
  126.     about: TTabSheet;
  127.     PopupMenu1: TPopupMenu;
  128.     MenuItem3: TMenuItem;
  129.     MenuItem4: TMenuItem;
  130.     Panel20: TPanel;
  131.     Label20: TLabel;
  132.     TxtAbout: TRichEdit;
  133.     TabSheet19: TTabSheet;
  134.     TxtMemory: TRichEdit;
  135.     Label21: TLabel;
  136.     Panel21: TPanel;
  137.     Label22: TLabel;
  138.     ActionAutoPrint: TAction;
  139.     GridMemory: TStringGrid;
  140.     PrintWARNING1: TMenuItem;
  141.     N1: TMenuItem;
  142.     TestAll1: TMenuItem;
  143.     ActionTestAll: TAction;
  144.     TabSheet20: TTabSheet;
  145.     Panel22: TPanel;
  146.     Label23: TLabel;
  147.     TxtCreateFile: TRichEdit;
  148.     ActionFastCount: TAction;
  149.     ToolButton3: TToolButton;
  150.     procedure FormCreate(Sender: TObject);
  151.     procedure ListDemosChange(Sender: TObject; Node: TTreeNode);
  152.     procedure ActionCloseExecute(Sender: TObject);
  153.     procedure ActionReportUpdate(Sender: TObject);
  154.     procedure ActionUseOleExecute(Sender: TObject);
  155.     procedure ActionHtmlUpdate(Sender: TObject);
  156.     procedure ActionViewTemplateExcelUpdate(Sender: TObject);
  157.     procedure ActionUseTStoreExecute(Sender: TObject);
  158.     procedure ActionUseNativeExecute(Sender: TObject);
  159.     procedure ActionViewTemplateExcelExecute(Sender: TObject);
  160.     procedure ActionReportExecute(Sender: TObject);
  161.     procedure ActionPreviewUpdate(Sender: TObject);
  162.     procedure ActionPreviewExecute(Sender: TObject);
  163.     procedure btnOpenMyImageClick(Sender: TObject);
  164.     procedure ActionViewTemplateInternalExecute(Sender: TObject);
  165.     procedure ActionAutoPrintExecute(Sender: TObject);
  166.     procedure ActionTestAllExecute(Sender: TObject);
  167.     procedure ActionFastCountExecute(Sender: TObject);
  168.   private
  169.     DemoEdit: TDemoEdit;
  170.     DlgReport: TReport;
  171.     Directory: string;
  172.  
  173.     procedure FillGridVarArray(const GridVarArray: TStringGrid);
  174.     procedure DoReport(const Preview: boolean; const Automatic: boolean);
  175.     procedure DoImport;
  176.     procedure DoCreateFile(const Automatic: boolean);
  177.     procedure FillGridMemory(const GridMemory: TStringGrid);
  178.     { Private declarations }
  179.   public
  180.     { Public declarations }
  181.   end;
  182.  
  183. var
  184.   Main: TMain;
  185.  
  186. implementation
  187.  
  188. {$R *.DFM}
  189.  
  190. procedure TMain.FillGridVarArray(const GridVarArray: TStringGrid);
  191. var
  192.   i,k: integer;
  193. begin
  194.   for i:=1 to GridVarArray.ColCount-1 do GridVarArray.Cells[ i , 0]:= chr(ord('A')+i-1);
  195.   for i:=1 to GridVarArray.RowCount-1 do GridVarArray.Cells[ 0 , i]:= IntToStr(i+3);
  196.   for i:=1 to GridVarArray.ColCount-1 do
  197.     for k:=1 to GridVarArray.RowCount-1 do
  198.       GridVarArray.Cells[ i , k]:= IntToStr(Random(5));
  199.   GridVarArray.Cells[3,2]:='FlexCel';
  200. end;
  201.  
  202. procedure TMain.FillGridMemory(const GridMemory: TStringGrid);
  203. var
  204.   i: integer;
  205. begin
  206.   GridMemory.RowCount:=500;
  207.   GridMemory.Cells[0,0]:='Number';
  208.   GridMemory.Cells[1,0]:='Name';
  209.   GridMemory.Cells[2,0]:='Date';
  210.   GridMemory.Cells[3,0]:='Sex';
  211.   for i:=1 to GridMemory.RowCount-1 do
  212.   begin
  213.     GridMemory.Cells[ 0 , i]:= IntToStr(i);
  214.     GridMemory.Cells[ 1 , i]:= 'Test'+IntToStr(i);
  215.     GridMemory.Cells[ 2 , i]:= DateToStr(Now-random(365*50));
  216.     if Random(2)=0 then GridMemory.Cells[ 3 , i]:= 'M' else GridMemory.Cells[ 3 , i]:= 'F';
  217.   end;
  218.  
  219.   GridMemory.Cells[1,1]:='Adrian';
  220.   GridMemory.Cells[2,1]:='8/9/1972';
  221.   GridMemory.Cells[3,1]:='M';
  222.   GridMemory.Cells[1,2]:='Agus';
  223.   GridMemory.Cells[2,2]:='2/3/2002';
  224.   GridMemory.Cells[3,2]:='F';
  225.   GridMemory.Cells[1,3]:='Zoe';
  226.   GridMemory.Cells[2,3]:='1/7/1939';
  227.   GridMemory.Cells[3,3]:='F';
  228.   for i:=1 to GridMemory.RowCount-1 do GridMemory.Cells[ 0 , i]:= IntToStr(i);
  229.  
  230. end;
  231.  
  232. procedure TMain.FormCreate(Sender: TObject);
  233. var
  234.   i:integer;
  235.   ExePath: string;
  236. begin
  237.   try
  238.     for i:=0 to Tabs.PageCount-1 do Tabs.Pages[i].TabVisible:=false;
  239.     ListDemos.FullExpand;
  240.  
  241.     ExePath:=ExtractFilePath(ParamStr(0));
  242.     for i:=0 to ComponentCount-1 do if (Components[i] is TRichEdit) and (copy(Components[i].Name,1,3)='Txt') then
  243.       (Components[i] as TRichEdit).Lines.LoadFromFile( ExePath +'FlDemoSheets\'+ copy(Components[i].Name,4,length(Components[i].Name))+'.rtf');
  244.  
  245.     edSQL.Text:='select * from customer'; //Sometimes it gets deleted if written directly into the designer
  246.     FillGridVarArray(GridVarArray1);
  247.     FillGridVarArray(GridVarArray2);
  248.     FillGridMemory(GridMemory);
  249.  
  250.     edMyImage.Text:= ExePath+'FlexCel.bmp';
  251.   except
  252.     on e: Exception do
  253.     begin
  254.       Application.ShowException(e);
  255.       ShowMessage('Make sure you have unzipped all the files');
  256.       Application.Terminate;
  257.     end;
  258.   end;//Except
  259. end;
  260.  
  261. procedure TMain.ListDemosChange(Sender: TObject; Node: TTreeNode);
  262. begin
  263.   Tabs.ActivePageIndex:= Node.AbsoluteIndex;
  264.   if Tabs.ActivePage.Tag=4 then DemoData.Cust.Open else DemoData.Cust.Close;
  265. end;
  266.  
  267. procedure TMain.ActionCloseExecute(Sender: TObject);
  268. begin
  269.   Close;
  270. end;
  271.  
  272. procedure TMain.DoReport(const Preview: boolean; const Automatic: boolean);
  273. var
  274.   Dlg: TSaveDialog;
  275.   StartTime, EndTime: TDateTime;
  276. begin
  277.   StatusBar.SimpleText:='';
  278.   //Process Options
  279.   if BtnUseNative.Down then
  280.     DemoData.SetAdapter(DemoData.XLSAdapter) else
  281.     DemoData.SetAdapter(DemoData.OLEAdapter);
  282.  
  283.   DemoData.Protect:= BtnProtect.Down;
  284.  
  285.   //if it's native or HTML, ask the user for a filename
  286.   Dlg:=nil;
  287.   if BtnUseNative.Down then Dlg:=DemoData.XlsSaveDialog
  288.   else if BtnHTML.Down then Dlg:=DemoData.HTMLSaveDialog;
  289.  
  290.   if Automatic then
  291.   begin
  292.     Dlg:=nil;
  293.     DemoData.SetFileName(Directory+'\TestReport'+IntToStr(Tabs.ActivePage.Tag)+'.xls');
  294.     if FileExists(Directory+'\TestReport'+IntToStr(Tabs.ActivePage.Tag)+'.xls') then DeleteFile(Directory+'\TestReport'+IntToStr(Tabs.ActivePage.Tag)+'.xls');
  295.   end;
  296.  
  297.   if Dlg<>nil then
  298.   begin
  299.     if not Dlg.Execute then exit;
  300.     DemoData.SetFileName(Dlg.FileName);
  301.     if FileExists(Dlg.FileName) then DeleteFile(Dlg.FileName);
  302.   end;
  303.   Application.ProcessMessages;
  304.  
  305.   if Tabs.ActivePage.Tag=2 then DemoData.FillArrayDemo([GridVarArray1, GridVarArray2]);
  306.   if Tabs.ActivePage.Tag=3 then DemoData.MyImageFilename:=edMyImage.Text;
  307.   if Tabs.ActivePage.Tag=6 then DemoData.Cust.Open;
  308.   DemoData.Cust.Filtered:= Tabs.ActivePage.Tag=6; //So we dont use so many records
  309.   if BtnUseNative.Down then DemoData.RepPivot.Template:='Templates\PivotDemo AutoOpen.xls' else DemoData.RepPivot.Template:='Templates\PivotDemo.xls';
  310.   if Tabs.ActivePage.Tag=11 then DemoData.Ds.SQL:= edSQL.Lines;
  311.   if Tabs.ActivePage.Tag=13 then DemoData.FillMemTable(GridMemory);
  312.   {$IFNDEF Excel97}
  313.     DemoData.OLEAdapter.SaveFormatBasic:=[saHtml];
  314.     DemoData.GetReport(Tabs.ActivePage.Tag).AutoClose:= BtnHTML.Down and BtnHTML.Enabled;
  315.   {$ENDIF}
  316.  
  317.   //Run the report
  318.   StartTime:=Now;
  319.   DemoData.GetReport(Tabs.ActivePage.Tag).Run;
  320.   EndTime:=Now;
  321.   StatusBar.SimpleText:=Format('Last Report took: %f seconds', [(EndTime-StartTime)*24*3600]);
  322.  
  323.   if Dlg<>nil then
  324.   begin
  325.     if Preview then
  326.     begin
  327.       if DlgReport= nil then DlgReport:=TReport.Create(Self);
  328.       DlgReport.WB.Navigate(Dlg.FileName);
  329.       try
  330.         DlgReport.ShowModal;
  331.       finally
  332.         FreeAndNil(DlgReport); //only way I've seen to free document
  333.       end; //finally
  334.     end
  335.     else
  336.       if DemoData.AutoPrint then
  337.         ShellExecute( Handle,'print', PCHAR(Dlg.FileName), NIL,NIL, SW_Hide)
  338.         else ShellExecute( Handle,'open', PCHAR(Dlg.FileName), NIL,NIL, SW_SHOW);
  339.   end;
  340. end;
  341.  
  342. procedure TMain.DoImport;
  343. begin
  344.   if not DemoData.OpenDialog.Execute then exit;
  345.   Application.ProcessMessages;
  346.   if BtnUseNative.Down then
  347.     DemoData.SetAdapter(DemoData.XLSAdapter) else
  348.     DemoData.SetAdapter(DemoData.OLEAdapter);
  349.  
  350.   DemoData.XLSAdapter.TemplateStore:=nil;
  351.   try
  352.     DemoData.FlexCelImport.OpenFile(DemoData.OpenDialog.FileName);
  353.   finally
  354.     ActionUseTStore.Execute;
  355.   end;//finally
  356.   try
  357.     if DemoEdit=nil then DemoEdit:=TDemoEdit.Create(Self);
  358.     DemoEdit.Caption:=Format(TxtEditing, [DemoData.OpenDialog.FileName]);
  359.     DemoEdit.FillData;
  360.     DemoEdit.ShowModal;
  361.   finally
  362.     DemoData.FlexCelImport.CloseFile;
  363.   end; //finally
  364.  
  365. end;
  366.  
  367. procedure TMain.DoCreateFile(const Automatic: boolean);
  368. var
  369.   Fi: TFlexCelImport;
  370.   FName: string;
  371.   w: widestring;
  372. begin
  373.   if BtnUseNative.Down then
  374.     DemoData.SetAdapter(DemoData.XLSAdapter) else
  375.     DemoData.SetAdapter(DemoData.OLEAdapter);
  376.  
  377.   if Automatic then
  378.     FName:=Directory+'\TestImport'+IntToStr(Tabs.ActivePage.Tag)+'.xls'
  379.   else
  380.   begin
  381.     if not DemoData.XlsSaveDialog.Execute then exit;
  382.     FName:=DemoData.XlsSaveDialog.FileName;
  383.   end;
  384.  
  385.   if FileExists(FName) then DeleteFile(FName);
  386.  
  387.   Fi:=DemoData.FlexCelImport;
  388.   Fi.OpenFile(ExtractFilePath(ParamStr(0))+'\Templates\NewFile.xls');
  389.   Fi.CellValue[6,1]:=integer(Fi.ColorPalette[3]);
  390.   Fi.ColorPalette[3]:=Rgb(0,200,20);
  391.   Fi.CellValue[6,2]:=integer(Fi.ColorPalette[3]);
  392.  
  393.   Fi.CellValue[3,3]:=5;
  394.   Fi.CellFormat[2,2]:=Fi.CellFormat[1,1];
  395.   Fi.CellValue[2,1]:='Test';
  396.   Fi.CellValue[3,1]:='TΘst';
  397.   w:=WideChar($266b);
  398.   Fi.CellValue[4,1]:=w;
  399.  
  400.   Fi.RowHeight[3]:=1000;
  401.   Fi.ColumnWidth[4]:=2000;
  402.   Fi.RowHeight[4]:=4000;
  403.   Fi.CellValue[1,3]:=Fi.RowHeight[4];
  404.   Fi.AutoRowHeight[4]:=true;
  405.   Fi.CellValue[1,4]:=Fi.RowHeight[4];
  406.  
  407.   Fi.ActiveSheet:=2;
  408.   Fi.CellValue[1,1]:=Fi.RowFormat[6];
  409.   Fi.CellValue[1,2]:=Fi.ColumnFormat[2];
  410.   Fi.CellValue[6,1]:='Testing';
  411.   //Fi.CellValue[6,2]:='Testing';
  412.   Fi.CellValue[6,3]:='Testing';
  413.   Fi.RowFormat[6]:=Fi.FormatListCount-1;
  414.   Fi.ColumnFormat[2]:=Fi.FormatListCount-2;
  415.   Fi.CellValue[2,1]:=Fi.RowFormat[6];
  416.   Fi.CellValue[2,2]:=Fi.ColumnFormat[2];
  417.   Fi.CellValue[6,4]:='Testing';
  418.  
  419.  
  420.   Fi.Save(FName);
  421.   Fi.CloseFile;
  422.   //Just to test I can read what I wrote...
  423.   Fi.OpenFile(FName);
  424.   Fi.CloseFile;
  425. end;
  426.  
  427.  
  428. procedure TMain.ActionReportUpdate(Sender: TObject);
  429. begin
  430.   ActionReport.Enabled:= Tabs.ActivePage.Tag>0;
  431.   if Tabs.ActivePage.Tag<>100 then
  432.   begin
  433.     ActionReport.ImageIndex:= 13;
  434.     ActionReport.Caption:='Report !';
  435.   end else
  436.   begin
  437.     ActionReport.ImageIndex:= 0;
  438.     ActionReport.Caption:='Import !';
  439.   end;
  440. end;
  441.  
  442. procedure TMain.ActionUseOleExecute(Sender: TObject);
  443. begin
  444.  //
  445. end;
  446.  
  447. procedure TMain.ActionHtmlUpdate(Sender: TObject);
  448. begin
  449.   ActionUseNative.Checked:=  BtnUseNative.Down;
  450.   ActionUseOle.Checked:=  BtnUseOle.Down and (Tabs.ActivePage.Tag<100);
  451.   ActionProtect.Enabled:=ActionUseOle.Checked and (Tabs.ActivePage.Tag<100);
  452.   ActionUseTStore.Enabled:=ActionUseNative.Checked and (Tabs.ActivePage.Tag<100);
  453.   ActionAutoPrint.Enabled:=(Tabs.ActivePage.Tag<100);
  454.   ActionFastCount.Enabled:=(Tabs.ActivePage.Tag>0)and(Tabs.ActivePage.Tag<100);
  455.  
  456.   {$IfDef Excel97}
  457.   ActionHTML.Enabled:=false;
  458.   {$Else}
  459.   ActionHtml.Enabled:=ActionUseOle.Checked and (Tabs.ActivePage.Tag<100);
  460.   {$Endif}
  461.  
  462. end;
  463.  
  464. procedure TMain.ActionViewTemplateExcelUpdate(Sender: TObject);
  465. begin
  466.   ActionViewTemplateExcel.Enabled:=ActionReport.Enabled and (Tabs.ActivePage.Tag<100);
  467.   ActionViewTemplateInternal.Enabled:=ActionViewTemplateExcel.Enabled;
  468. end;
  469.  
  470. procedure TMain.ActionUseTStoreExecute(Sender: TObject);
  471. begin
  472.   if DemoData.XlsTemplateStore.Templates.Count=0 then
  473.   begin
  474.     showmessage('For size considerations in the zipped file, this demo has the template store empty. If you want to use it, edit the unit UFLDemoData, double click the store, and add all the files from the folder "Templates"');
  475.     BtnUseTStore.Down:=false;
  476.     exit;
  477.   end;
  478.  
  479.  
  480.   if BtnUseTStore.Down then
  481.    DemoData.XLSAdapter.TemplateStore:=DemoData.XlsTemplateStore
  482.   else DemoData.XLSAdapter.TemplateStore:=nil;
  483. end;
  484.  
  485. procedure TMain.ActionUseNativeExecute(Sender: TObject);
  486. begin
  487.   //
  488. end;
  489.  
  490. procedure TMain.ActionViewTemplateExcelExecute(Sender: TObject);
  491. var
  492.   WaitCursor: IWaitCursor;
  493. begin
  494.   WaitCursor:=TWaitCursor.Create;
  495.   BtnViewTemplate.Action:=ActionViewTemplateExcel;
  496.   ShellExecute( Handle,'open', PCHAR(ExtractFilePath(Paramstr(0))+DemoData.GetReport(Tabs.ActivePage.Tag).Template), NIL,NIL, SW_SHOW);
  497. end;
  498.  
  499. procedure TMain.ActionViewTemplateInternalExecute(Sender: TObject);
  500. var
  501.   WaitCursor: IWaitCursor;
  502. begin
  503.   WaitCursor:=TWaitCursor.Create;
  504.   BtnViewTemplate.Action:=ActionViewTemplateInternal;
  505.   InvokeExcelEditor( DemoData, ExtractFilePath(Paramstr(0))+DemoData.GetReport(Tabs.ActivePage.Tag).Template);
  506. end;
  507.  
  508. procedure TMain.ActionReportExecute(Sender: TObject);
  509. var
  510.   WaitCursor: IWaitCursor;
  511. begin
  512.   WaitCursor:=TWaitCursor.Create;
  513.   if Tabs.ActivePage.Tag<100 then DoReport(false, false) else
  514.   if Tabs.ActivePage.Tag=100 then DoImport else DoCreateFile(false);
  515. end;
  516.  
  517. procedure TMain.ActionPreviewUpdate(Sender: TObject);
  518. begin
  519.   ActionPreview.Enabled:= ActionViewTemplateExcel.Enabled and
  520.      (not BtnUseOle.Down  or BtnHTML.Down);
  521. end;
  522.  
  523. procedure TMain.ActionPreviewExecute(Sender: TObject);
  524. var
  525.   WaitCursor: IWaitCursor;
  526. begin
  527.   WaitCursor:=TWaitCursor.Create;
  528.   DoReport(true, false);
  529. end;
  530.  
  531. procedure TMain.btnOpenMyImageClick(Sender: TObject);
  532. begin
  533.   if not DemoData.OpenPictureDialog.Execute then exit;
  534.   edMyImage.Text:= DemoData.OpenPictureDialog.FileName;
  535. end;
  536.  
  537.  
  538. procedure TMain.ActionAutoPrintExecute(Sender: TObject);
  539. var
  540.   WaitCursor:IWaitCursor;
  541. begin
  542.   if MessageDlg('This will print the report into a printer!'#10'Make sure you have a printer connected before you try'#10#10'Also, if in NATIVE mode, do not print reports with formulas'#10#10'┐CONTINUE?',
  543.                 mtWarning,[mbYes, mbNo], 0)<> mrYes then exit;
  544.  
  545.   WaitCursor:=TWaitCursor.Create;
  546.   DemoData.AutoPrint:=true;
  547.   try
  548.     if Tabs.ActivePage.Tag<100 then DoReport(false, false);
  549.   finally
  550.     DemoData.AutoPrint:=false;
  551.   end; //finally
  552. end;
  553.  
  554. procedure TMain.ActionTestAllExecute(Sender: TObject);
  555. var
  556.   WaitCursor:IWaitCursor;
  557.   i: integer;
  558. begin
  559.   if MessageDlg('This is a test I use to check the suite for memory leaks and more'#10'It will run all the reports and can take some time to complete'#10#10'┐CONTINUE?',
  560.                 mtWarning,[mbYes, mbNo], 0)<> mrYes then exit;
  561.  
  562.   WaitCursor:=TWaitCursor.Create;
  563.  
  564.   Directory:='';
  565.   if not SelectDirectory('Select the folder to store the reports','', Directory) then exit;
  566.  
  567.   ListDemos.FullCollapse;
  568.   for i:=0 to Tabs.PageCount-1 do
  569.     if (Tabs.Pages[i].Tag>0)and (Tabs.Pages[i].Tag<>100) then
  570.     begin
  571.       Tabs.ActivePageIndex:=i;
  572.       Application.ProcessMessages;
  573.       if Tabs.Pages[i].Tag<100 then DoReport(false, true) else DoCreateFile(true);
  574.     end;
  575.  
  576.   ListDemos.FullExpand;
  577.   ListDemos.Selected:=ListDemos.Items[1];
  578.   ListDemos.Selected:=ListDemos.Items[0];
  579. end;
  580.  
  581.  
  582. procedure TMain.ActionFastCountExecute(Sender: TObject);
  583. begin
  584.   ActionFastCount.Checked:=not ActionFastCount.Checked;
  585.   DemoData.ChangeFastCount(ActionFastCount.Checked);
  586. end;
  587.  
  588. end.
  589.