Home General

Access TChart component by name?

Hi,
Is it possible to access the TChart component by its component name? It would be very handy, with 9 different TeeChart graphs on the RB report, and most of the processing the same. This would avoid maintaining 9 basically identical pieces of code, one for each graph. Many of the items, like titles and axis minimums and maximums are already stored in arrays, I am thinking something like:

var
myTeeChart: TPPTeeChart;
begin
if GraphOneDo then
myTeeChart= 'ppTeeChart1';
graphNum:= 1;
BuildGraph(graphNum,myTeeChart);
if GraphTwoDo then ... like GraphOne, etc.
end;

procedure BuildGraph(GrNum,TeeName)
with TeeName do begin
Chart.Title.Caption:= TitleArrStr[1];//form wide var for graph 1
//and more with stored axis min, max, names in form wide variables
end;

I tried passing the TeeChart component name various ways.

Thanks if any insight on this.

Scott

Comments

  • I have found a solution to my own question, which is a basic delphi programming question more than a RB question. Until I was faced with 150 lines of code to maintain for each of 9 different graphs, I generally wrote code to maintain each component on a form, or at least did not see how to fill in the graph characteristics and fill the data for all 9 TeeCharts without duplicating a lot of code.
    So here is a brief example of what I am talking about:

    procedure TXRptRepHist.ppSummaryBand1BeforeGenerate(Sender: TObject);
    var
    year,chartNum: integer;
    thisTeeChart: TPPTeeChart;
    procedure TXRptRepHist.ppSummaryBand1BeforeGenerate(Sender: TObject);
    begin
    year:= 2019; //set vars to be used by all charts
    for chartNum:= 1 to 2 do begin
    case chartNum of
    1: thisTeeChart := ppTeeChart1;
    2: thisTeeChart := ppTeeChart2;
    end; //add more teechart cases here
    with thisTeeChart do begin
    Chart.LeftAxis.Maximum:= ColMax[chartNum];
    Chart.LeftAxis.Minimum:= ColMin[chartNum];
    //add data and other db stored characteristics for the specific chartNum as above
    //add some generic style characteristics for all charts as below
    Chart.BottomAxis.Maximum:= 12;
    Chart.BottomAxis.Minimum:= 0;
    Chart.Series[0].Title:= IntToStr(year);
    Chart.Series[1].Title:= IntToStr(year-1);
    Chart.Series[2].Title:= IntToStr(year-2);
    end; // with for thisTeeChart
    end; //loop for charts
    end;
  • Hi Scott,

    1. Delphi

    The Form/DataModule is typically the Owner of the Report and its elements. You can use the owner's FindComponent(aName) method to return the component with the specified name and then typecast the result.

    2. RB

    The Report.FindUserObject(aUserName) returns the object with the specified UserName and then typecast the result. The UserName is a property of each RB component. When the name is ppTeeChart1, the UserName defaults too TeeChart1. The UserName is displayed in the report designer object tree, and can be changed via the object inspector.

    Another options is to iterate over the Report.Bands[ ].Objects[ ] using the 'is' operator to check for a specific class type such as TppTeeChart




    Best regards,

    Nard Moseley
    Digital Metaphors
    www.digital-metaphors.com
Sign In or Register to comment.