• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 256
  • Last Modified:

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.
0
mcmahling
Asked:
mcmahling
1 Solution
 
Ralf KlattPrincipal ConsultantCommented:
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

Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now