Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Referencing components dynamically added to a Quick Report

Status
Not open for further replies.

StevenK

Programmer
Jan 5, 2001
1,294
GB
I have an application whereby I add components (TQRMemo's) dynamically to the target QuickReport. I do this according to a user selection using syntax :
with TQRMemo.Create(Nil) do
begin
{set up properties and Parent}
end;
I also incorporate a line which provides the added components with appropriate names - i.e. Name := 'QRMemo' + IntToStr(i) {incrementing the value of i accordingly}
I then seem to be unable to make references to these components.
The report is generated correctly but on instructing Delphi to list the components I do not see the names 'QRMemo1', 'QRMemo2', etc. as I expect - in fact I see no component names for QRMemos.
Can anyone suggest how I can then reference the added components ?
Thanks in advance
Steve
 
Hi Steven

I don't know if this is relevant to Qreports, but I use this function to reference display panels in one of my apps, the panels are created dynamicly and named in the same way you are creating your memos. Each panel has smaller panels and some edit boxes on it. the function uses Findcomponent to locate the dynamicly created things.

Procedure TMotorControl.StatusUpdate(m: integer; Amps: integer);
var Panel,SubPan,Gauge: TComponent;
begin
Panel := findcomponent('motor' + inttostr(m));
{test for nil return here to prevent crashes}
if panel <> nil then
begin
with Panel do
SubPan := findcomponent('ContPan' + inttostr(m));
with SubPan do
begin
Gauge := findcomponent('IGauge' + inttostr(m));
TEdit(Gauge).Text := inttostr(Amps);

Gauge := findcomponent('Status' + inttostr(m));
TEdit(Gauge).Text := displaybits;

Gauge := findcomponent('Fault' + inttostr(m));
if data[3] > 16 then data[3] := 0;
TEdit(Gauge).Text := inttostr(data[3])
end
end
end;


Hope this is of some help Steve
 
The Components list only holds controls &quot;owned&quot; by your form. Since you passed nil for the owner in the constructor, this control has no owner.

Instead, try TQRMemo.Create(self) (assuming that this is inside a member function of your form). This will make the form the 'owner' of the QRMemos so they will show up in the components list.

Another side effect of this is that you will not need to free these QRMemos. Since the form is the owner they will be freed when the form is freed. If you were not freeing them by hand before, you had a memory leak. :)

Good luck!
TealWren
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top