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.
mcmahlingAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Ralf KlattEmployee in Civil ServiceCommented:
Hi,

This piece of code might do the trick:


var
I: Integer;
for I:= Scollbox1.ComponentCount - 1 downto 0 do
if Scrollbox1.Components[I] is TEdit then
TEdit(Scrollbox1.Components[I]).Free
else
if Scrollbox1.Components[I] is TLabel then
TLabel(Scrollbox1.Components[I]).Free
for I:= Scollbox1.ComponentCount - 1 downto 0 do
TEdit(Scrollbox1.Components[I]).free;


You'll have to fit it to your own code!


Best regards,
Raisor
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Programming

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.