Delphi - Changing Chart Title in Excel causes AV - Updated with complete sample -


i using delphi seattle build , display chart in excel (2013). build chart pivot table. chart displays fine. has default title, want change that. should simple property change, keep getting av errors. when google, closest thing can find mentions need select chart and/or chart title before change it. [updated] here working sample shows problem.

procedure tform1.button1click(sender: tobject); var   oexcel : excelapplication;   rawdatasheet :_worksheet;   mychart: shape; begin     oexcel := createoleobject('excel.application') excelapplication;     oexcel.visible[locale_user_default] := true;     // add new workbook, single sheet    oexcel.workbooks.add(emptyparam, locale_user_default);    // handle active sheet, , insert dummy data    rawdatasheet :=  oexcel.activesheet _worksheet;    rawdatasheet.range['a1', 'b10'].value2 := 10;      // add chart     mychart := rawdatasheet.shapes.addchart2(208, xlcolumnclustered, 200, 10,  300, 300, true);      // try access chart title...  avs here.     mychart.chart.hastitle[locale_user_default] := true;      // set title text.  if comemnt out above line, avs     mychart.chart.charttitle[locale_user_default].caption := 'new chart title';  end; 

i cannot find way change title. can't find way read existing title, let alone change it.

the microsoft object model documentation charttitle says correct property...(https://msdn.microsoft.com/en-us/library/office/ff840521.aspx)

additional info: did generate own type library, excel_tlb, , have in uses clause. complete uses clause is...

uses   winapi.windows, winapi.messages, system.sysutils, system.variants, system.classes, vcl.graphics,   vcl.controls, vcl.forms, vcl.dialogs, vcl.stdctrls, comobj, excel_tlb; 

i able set title below. difference select chart able refer through activechart. note have office 14 doesn't have addchart2, used addchart.

uses   comobj, excel_tlb;  {$r *.dfm}  procedure tform1.button1click(sender: tobject); var   oexcel : excelapplication;   rawdatasheet :_worksheet;   mychart: shape; begin     oexcel := createoleobject('excel.application') excelapplication;     oexcel.visible[locale_user_default] := true;     // add new workbook, single sheet    oexcel.workbooks.add(emptyparam, locale_user_default);    // handle active sheet, , insert dummy data    rawdatasheet :=  oexcel.activesheet _worksheet;    rawdatasheet.range['a1', 'b10'].value2 := 10;      // add chart //    mychart := rawdatasheet.shapes.addchart2(208, xlcolumnclustered, 200, 10,  300, 300, true);     mychart := rawdatasheet.shapes.addchart(xlcolumnclustered, 200, 10,  300, 300);     mychart.select(false);      oexcel.activechart.hastitle[locale_user_default] := true;     oexcel.activechart.charttitle[locale_user_default].caption := 'new chart title'; end; 

also note, don't know implication of parameter that's passed select.


another option works let go of type safety after point (where doesn't work anymore) , rely on vba examples found on ms documentation (which not match signatures of generated type library). allowed work on chart directly.

procedure tform1.button1click(sender: tobject); var   oexcel : excelapplication;   rawdatasheet :_worksheet;   mychart: shape;   v: olevariant; begin     oexcel := createoleobject('excel.application') excelapplication;     oexcel.visible[locale_user_default] := true;     // add new workbook, single sheet    oexcel.workbooks.add(emptyparam, locale_user_default);    // handle active sheet, , insert dummy data    rawdatasheet :=  oexcel.activesheet _worksheet;    rawdatasheet.range['a1', 'b10'].value2 := 10;      // add chart //    mychart := rawdatasheet.shapes.addchart2(208, xlcolumnclustered, 200, 10,  300, 300, true);     mychart := rawdatasheet.shapes.addchart(xlcolumnclustered, 200, 10,  300, 300);      v := mychart.chart;     v.hastitle := true;     v.charttitle.caption := 'chart title'; end; 

Comments

Popular posts from this blog

account - Script error login visual studio DefaultLogin_PCore.js -

xcode - CocoaPod Storyboard error: -