Board index » delphi » Excel Chart (lcid?)

Excel Chart (lcid?)

I am creating a chart in Excel in the following manner:

var
  ExcelApp,Chart:Variant;
begin
  ...
  ExcelApp.Charts.Add;
  Chart:=ExcelApp.ActiveChart;
  ...
end;

If I attempt to call: Chart.HasTitle:=True; or
Chart.ChartTitle.Caption:='Some Text'; then I get an Ole error 800A01A8.
When I look at _ChartDisp, I notice that HasTitle has a [lcid:integer] after
it, unlike other instances of HasTitle, such as off of Axis.  What is this
"lcid" and how do I need to call HasTitle and other properties which have
this?

Thanks,

Barney

 

Re:Excel Chart (lcid?)


lcid is is the locale context.
You should use the LOCALE_USER_DEFAULT constant as the value of lcid.

Quote
"Barney Mattox" <stri...@logrus.com> wrote in message

news:3b4abb20$1_1@dnews...
Quote
> I am creating a chart in Excel in the following manner:

> var
>   ExcelApp,Chart:Variant;
> begin
>   ...
>   ExcelApp.Charts.Add;
>   Chart:=ExcelApp.ActiveChart;
>   ...
> end;

> If I attempt to call: Chart.HasTitle:=True; or
> Chart.ChartTitle.Caption:='Some Text'; then I get an Ole error
800A01A8.
> When I look at _ChartDisp, I notice that HasTitle has a

[lcid:integer] after
Quote
> it, unlike other instances of HasTitle, such as off of Axis.  What
is this
> "lcid" and how do I need to call HasTitle and other properties which
have
> this?

> Thanks,

> Barney

Re:Excel Chart (lcid?)


Quote
> lcid is is the locale context.
> You should use the LOCALE_USER_DEFAULT constant as the value of lcid.

I tried using this constant.  I also tried using the GetUserDefaultLCID
function as demonstrated in a post elsewhere for an unrelated topic.  My
current code looks like this and still generates the same error (see
comments):

procedure TForm1.Button1Click(Sender: TObject);
var
  Sheet1,Sheet2,Chart,Range:Variant;
  lcid:integer;
begin
  ExcelApplication := CreateOLEObject('Excel.Application');
  try
    lcid:=GetUserDefaultLCID;
    ExcelApplication.Visible := True;
    ExcelApplication.Workbooks.Add;
    ExcelApplication.Worksheets['Sheet1'].Visible:=True;
    ExcelApplication.Worksheets['Sheet1'].Name:='ChartTest';
    ExcelApplication.Worksheets['Sheet2'].Visible:=True;
    ExcelApplication.Worksheets['Sheet2'].Name:='ChartData';
    PopulateData('ChartData');  // just fills in some sample numbers
    Sheet1:=ExcelApplication.Worksheets['ChartTest'];
    Sheet2:=ExcelApplication.Worksheets['ChartData'];
    Sheet2.Select;
    Range:=ExcelApplication.Range['A1:D13'];
    Sheet1.Select;
    ExcelApplication.Charts.Add;
    Chart:=ExcelApplication.ActiveChart;
    Chart.ApplyCustomType(xlBuiltIn,'Line - Column on 2 Axes');
    Chart.SetSourceData(Range,xlColumns);
    Chart.Location(xlLocationAsObject,'ChartTest');
    Chart.HasTitle[lcid]:=True;  // Generates: OLE error 800A01A8
    // Chart.HasTitle[LOCALE_USER_DEFAULT];  // Same Error
  finally
    // Do nothing for now
  end;
end;

Any feedback is welcomed.

Thanks,

Barney

Other Threads