diff --git a/components/fpspreadsheet/examples/visual/fpschart/fpschartlink/main.lfm b/components/fpspreadsheet/examples/visual/fpschart/fpschartlink/main.lfm index 76bfd4140..6708d0a99 100644 --- a/components/fpspreadsheet/examples/visual/fpschart/fpschartlink/main.lfm +++ b/components/fpspreadsheet/examples/visual/fpschart/fpschartlink/main.lfm @@ -6,7 +6,7 @@ object Form1: TForm1 Caption = 'Form1' ClientHeight = 527 ClientWidth = 1351 - LCLVersion = '3.99.0.0' + LCLVersion = '4.99.0.0' OnCreate = FormCreate object Splitter1: TSplitter Left = 523 @@ -109,6 +109,8 @@ object Form1: TForm1 Height = 375 Top = 1 Width = 521 + OnChange = sWorkbookTabControl1Change + TabHeight = 25 TabIndex = 0 Tabs.Strings = ( 'Sheet1' @@ -118,8 +120,8 @@ object Form1: TForm1 WorkbookSource = sWorkbookSource object sWorksheetGrid: TsWorksheetGrid Left = 2 - Height = 350 - Top = 23 + Height = 348 + Top = 25 Width = 517 FrozenCols = 0 FrozenRows = 0 @@ -151,8 +153,8 @@ object Form1: TForm1 TabOrder = 3 object Chart: TChart Left = 0 - Height = 489 - Top = 0 + Height = 464 + Top = 25 Width = 823 AxisList = < item @@ -173,6 +175,38 @@ object Form1: TForm1 ) Align = alClient end + object Panel4: TPanel + Left = 0 + Height = 25 + Top = 0 + Width = 823 + Align = alTop + BevelOuter = bvNone + ClientHeight = 25 + ClientWidth = 823 + TabOrder = 1 + Visible = False + object Label1: TLabel + AnchorSideTop.Control = Panel4 + AnchorSideTop.Side = asrCenter + Left = 0 + Height = 15 + Top = 5 + Width = 39 + Caption = 'Chart #' + end + object seChartIndex: TSpinEdit + AnchorSideTop.Control = Panel4 + AnchorSideTop.Side = asrCenter + Left = 48 + Height = 23 + Top = 1 + Width = 74 + Alignment = taRightJustify + TabOrder = 0 + OnChange = seChartIndexChange + end + end end object sWorkbookSource: TsWorkbookSource FileFormat = sfUser diff --git a/components/fpspreadsheet/examples/visual/fpschart/fpschartlink/main.pas b/components/fpspreadsheet/examples/visual/fpschart/fpschartlink/main.pas index 262c9fe6f..7feda2f22 100644 --- a/components/fpspreadsheet/examples/visual/fpschart/fpschartlink/main.pas +++ b/components/fpspreadsheet/examples/visual/fpschart/fpschartlink/main.pas @@ -5,11 +5,11 @@ unit main; interface uses - Classes, SysUtils, + Classes, Spin, SysUtils, LCLVersion, Forms, Controls, Graphics, Dialogs, ExtCtrls, StdCtrls, FileUtil, LazFileUtils, TAGraph, TASources, fpSpreadsheet, fpsTypes, fpsOpenDocument, xlsxOOXML, - fpSpreadsheetCtrls, fpSpreadsheetGrid, fpSpreadsheetChart; + fpSpreadsheetCtrls, fpSpreadsheetGrid, fpSpreadsheetChart, fpsChart; type @@ -20,6 +20,7 @@ type btnOpen: TButton; Chart: TChart; cbFileNames: TComboBox; + Label1: TLabel; lblFileNames: TLabel; ListChartSource: TListChartSource; Memo: TMemo; @@ -27,6 +28,8 @@ type Panel1: TPanel; Panel2: TPanel; Panel3: TPanel; + Panel4: TPanel; + seChartIndex: TSpinEdit; Splitter1: TSplitter; sWorkbookSource: TsWorkbookSource; sWorkbookTabControl1: TsWorkbookTabControl; @@ -35,7 +38,9 @@ type procedure btnOpenClick(Sender: TObject); procedure cbFileNamesSelect(Sender:TObject); procedure FormCreate(Sender: TObject); + procedure seChartIndexChange(Sender: TObject); procedure sWorkbookSourceError(Sender: TObject; const AMsg: String); + procedure sWorkbookTabControl1Change(Sender: TObject); private FDir: String; sChartLink: TsWorkbookChartLink; @@ -121,11 +126,40 @@ begin end; end; +procedure TForm1.seChartIndexChange(Sender: TObject); +var + charts: TsChartArray; + i: Integer; +begin + charts := sWorkbookSource.Worksheet.GetCharts; + i := seChartIndex.Value; + if i < 0 then i := 0; + if i > High(charts) then i := High(charts); + sChartLink.WorkbookChartIndex := charts[i].Index; +end; + procedure TForm1.sWorkbookSourceError(Sender: TObject; const AMsg: String); begin Memo.Lines.Add(AMsg); end; +procedure TForm1.sWorkbookTabControl1Change(Sender: TObject); +var + charts: TsChartArray; + n: Integer; +begin + charts := sWorkbookSource.Worksheet.GetCharts; + n := Length(charts); + if n > 1 then + begin + Panel4.Show; + seChartIndex.MaxValue := n - 1; + seChartIndex.Value := 0; + sChartLink.WorkbookChartIndex := charts[0].Index; + end else + Panel4.Hide; +end; + procedure TForm1.LoadFile(AFileName: String); var ext: String; @@ -156,7 +190,8 @@ begin sChartLink := TsWorkbookChartLink.Create(self); sChartLink.Chart := Chart; sChartLink.WorkbookSource := sWorkbookSource; - sChartLink.WorkbookChartIndex := 0; + + sWorkbookTabControl1Change(nil); end; end.