Access to object parent from delphi code
Hi!
Is it possible to access to parent objects from code?
for example, i have a function:
function prueba(Sender : TObject)...
var
obj : TppDetailBand;
begin
obj := TppDetailBand(Sender);
...
end;
Is is possible to access to "obj" parent for modify any property or access
to the other bands? I try to do this:
variable := TppChildReport(obj):
showmessage(inttostr(variable.BandCount));
but it returns me an error (....exception EAccessviolation whith message
'Access violation at adress....')
I try too to access from parent to children objects and returns the same
message. Is not possible that i'm trying to do?
Is it possible to access to parent objects from code?
for example, i have a function:
function prueba(Sender : TObject)...
var
obj : TppDetailBand;
begin
obj := TppDetailBand(Sender);
...
end;
Is is possible to access to "obj" parent for modify any property or access
to the other bands? I try to do this:
variable := TppChildReport(obj):
showmessage(inttostr(variable.BandCount));
but it returns me an error (....exception EAccessviolation whith message
'Access violation at adress....')
I try too to access from parent to children objects and returns the same
message. Is not possible that i'm trying to do?
This discussion has been closed.
Comments
If "obj" is in fact a TppDetailBand object, you would need to reference its
Parent property to successfully access its parent.
obj := TppDetailBand(Sender);
if (obj.Parent is TppChildReport) then
variable := TppChildReport(obj.Parent);
--
Regards,
Nico Cizik
Digital Metaphors
http://www.digital-metaphors.com
Nico Cizik
Digital Metaphors
http://www.digital-metaphors.com
1. A safe coding practice is to always test the object type prior to
typecasting.
if (Sender is TppDetailBand) then
lDetailBand := TppDetailBand(Sender);
2. Report structure
Report.Bands[ ].Objects[ ] describes the report layout
In the above, Report may be a TppReport or a TppChildReport
Band is a TppBand descendant. Use TppBand.Report to access the 'parent'
Object is a TppComponent descendant. Use TppComponent.Band to access the
'parent'
3. Subreport structure
Subreport.Report provides access to the TppChildReport
TppSubReport descends from TppComponent and can be placed on the band.
TppChildReport descends from TppCustomReport
--
Nard Moseley
Digital Metaphors
www.digital-metaphors.com
Best regards,
Nard Moseley
Digital Metaphors
www.digital-metaphors.com