Create TppComponents at runtime
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.
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.
This discussion has been closed.
Comments
the band. Try freeing the dbText after the call to RemoveObject.
BTW, you can reference the detail band by aReport.DetailBand or
uses
ppTypes;
...
lDetailBand: TppBand;
...
lDetailband := aReport.GetBand(btDetail, 0);
Cheers,
Jim Bennett
Digital Metaphors
http://www.digital-metaphors.com
info@digital-metaphors.com
ldbText.Free;
or
ldbText.Band := nil;
ldbText.Free;
Cheers,
Jim Bennett
Digital Metaphors
http://www.digital-metaphors.com
info@digital-metaphors.com