Hi all,
I have a question regarding TScrollBox. I have added a TScrollBox to a
TTabSheet at design time. At runtime, I use a TQuery to fetch records from a
table to determine the number of rows needed in the TScrollBox. Then, I add
4-6 TCheckBoxes and 1-3 TEdits per row to the TScrollBox. Sometimes this can
mean the addition of up to 200 of these rows, equating to 1200 TCheckBoxes
and 300 TEdits. Then another query is performed to determine which of these
rows need to have values set.
I use an object to represent each row (i.e., the TCheckBoxes and TEdits) and
add each object to a TList. I perform the primary TQuery and create the
objects (and add them to a TList) once. When I move to the next record, the
secondary query sets the approriate rows/fields. What is strange is that (I
am using the resource meter) when the TTabSheet with the TScrollBox on it is
selected, the items are drawn and system resources plummet. The items have
already been allocated and placed in the TScrollBox, so I am confused as to
the sudden performance hit upon selecting the TTabSheet containing the
TScrollBox.
The following is the object definition :
TService = class(TObject)
private
sLabel : TLabel;
sConAuth, sAuthReq, sCOD : TCheckBox;
sAuthLim, sNumAuth, sComments : TEdit;
sIdNo : integer;
Constructor Create(Scroll:TScrollBox; IdNo:Integer;
sCaption:String; Item:Integer);
Destructor Destroy; override;
procedure Show;
end;
The constructor creates the TLabel,TCheckBoxes and TEdits. Some properties
such as Top and Left are set and the items are initially not visible and not
enabled.
The Parent method is set to Scroll. The Create method is called within a
while loop bounded by a TQuery.EOF condition. After the create, the TService
instance is made visible and add to a TList. When a user queries a record,
the Boxes and Edits are filled based on another query. The TService
instances are Free(d) on FormDestroy (along with the TList) as follows :
procedure TfrmARCustomer.FormDestroy(Sender: TObject);
var
i : integer;
begin
if ServicesList <> nil then
begin
for i := 0 to ServicesList.Count - 1 do
TService(ServicesList[i]).Free;
if ServicesList.Count > 0 then
ServicesList.Clear;
end;
ScrollServices.DestroyComponents;
ServicesList.Free;
end;
ServicesList is of type TList and is Create(d) on FormCreate.
Any help/insight or willing to review the unit in its entirety is VERY
welcome ( and probably necessary!). I don't know if I'm just creating way
too many controls or if I'm mismanaging the TService objects or the TList.
Thanks in advance,
John Owen
Tom McLeod Software