We help IT Professionals succeed at work.

We've partnered with Certified Experts, Carl Webster and Richard Faulkner, to bring you two Citrix podcasts. Learn about 2020 trends and get answers to your biggest Citrix questions!Listen Now

x

Custom Component: Clearing the Component

mcmahling
mcmahling asked
on
Medium Priority
268 Views
Last Modified: 2010-04-17
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.
Comment
Watch Question

Employee in Civil Service
CERTIFIED EXPERT
Commented:
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

Not the solution you were looking for? Getting a personalized solution is easy.

Ask the Experts
Access more of Experts Exchange with a free account
Thanks for using Experts Exchange.

Create a free account to continue.

Limited access with a free account allows you to:

  • View three pieces of content (articles, solutions, posts, and videos)
  • Ask the experts questions (counted toward content limit)
  • Customize your dashboard and profile

*This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

OR

Please enter a first name

Please enter a last name

8+ characters (letters, numbers, and a symbol)

By clicking, you agree to the Terms of Use and Privacy Policy.