Home General
New Blog Posts: Merging Reports - Part 1 and Part 2

Create TppComponents at runtime

edited March 2002 in General
I am having a problem creating TppDBText components at runtime and adding
them to a report. I have to dynamically create a certain number of DBText
components each time the report is run and add them to the detail band. Each
time I run the report I have to remove any DBText components that I
previously created and possibly create and add new ones.

Everything works beautifully except when I close the form I'm getting access
violations. Here is the code I am using. Maybe someone can see a problem
with it.

// find the report detail band
lBand := nil;
for i := 0 to ( ppReport1.BandCount - 1 ) do
if ppReport1.Bands[ i ] is TppDetailBand then
begin
lBand := ppReport1.Bands[ i ];
break;
end;
if lBand <> nil then
begin
// remove previous DBText fields created at runtime
for i := ( lBand.ObjectCount - 1 ) downto 0 do
if lBand.Objects[ i ] is TppDBText then
if TppDBText( lBand.Objects[ i ] ).Tag = 1 then
lBand.RemoveObject( lBand.Objects[ i ] );
// add new custom DBText objects
for i := 0 to ( CustomFields.Count - 1 ) do
begin
lDBText := TppDBText.Create( lBand );
lBand.AddObject( lDBText );
with lDBText do
begin
Band := lBand;
UserName := 'DBText' + IntToStr( i + 1 );
Alignment := taRightJustify;
DataField := CustomFields.Strings[ i ];
DataPipeline := ppJITPipeline1;
Tag := 1;
// set other properties, width, left, etc...
end;
end;
end;


--
Kevin McBrearty
ATG Automation Technologies Group Ltd.

Comments

This discussion has been closed.