Link to home
Start Free TrialLog in
Avatar of mcmahling
mcmahling

asked on

Custom Component: Clearing the Component

I am using Delphi 2006 VCL.  In the following code I am creating a component ScrollBox with a series of DBCharts.  I have placed the component on a form.  When the form opens the scrollbox is displaced with the DBCharts.  The problem is that when I open the form again the DBCharts from the last time are persisting.  In other words, if I called for 3 DBCharts before and closed the form then called for only two charts the second time, I will see the two new charts plus the third of the 3 charts I did the first time.  How can I clear the scrollbox is the question?

unit MultiDBChart;

interface

uses
  Windows, Messages, SysUtils, Classes, Controls, ExtCtrls, DBChart;

type
  TMultiDBChart = class(TScrollBox)
  private
    nOnClickChart : TNotifyevent;
    procedure DoOnClick(Sender : TObject);
  public
    DBCharts : array of TDBChart;
    function add : integer;
  published
    property OnClickChart: TNotifyEvent read nOnClickChart write nOnClickChart;
  end;

procedure Register;

implementation

procedure Register;
begin
  RegisterComponents('Additional', [TMultiDBChart]);
end;

procedure TMultiDBChart.DoOnClick(Sender : TObject);
begin
  nOnClickChart(sender);
end;

function TMultiDBChart.add : integer;
var
  l : integer;
begin
  l:=Length(DBCharts);
  SetLength(DBCharts,l+1);
  DBCharts[l]:=TDBChart.create(self);
  with DBCharts[l] do
  begin
    parent := self;
    onclick := DoOnClick;
    //set width height and posittion of DBChart here.
  end;
  result := l
end;

end.
ASKER CERTIFIED SOLUTION
Avatar of Ralf Klatt
Ralf Klatt
Flag of Germany image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial