Access an owner procedure from a TPersistent class

I use in my component a TPersistent class . Here, before invalidate the owner, I need to access an owner procedure ( alike Prepare ).
How can I do that ?
LVL 9
ginsonicAsked:
Who is Participating?

Improve company productivity with a Business Account.Sign Up

x
 
DragonSlayerConnect With a Mentor Commented:
umm... either

1. Make it public

2. Create a new class

type
  THackMyDBGrid = class(TgnDBGrid)
  public
    procedure Prepare; // change visibility
  end;

THackMyDBGrid(Owner).Prepare;



:)
0
 
AloneCommented:
If your owner class and TPersistent descedant are in same unit, you can call all methods directly, because they are treated as "friendly" classes
0
 
ginsonicAuthor Commented:
Are you sure ?

Prepare; // [Error] test.pas(272): Undeclared identifier: 'Prepare'
FOwner.Invalidate;

Same result for FOwner.Prepare;
0
Get your problem seen by more experts

Be seen. Boost your question’s priority for more expert views and faster solutions

 
ginsonicAuthor Commented:
And please ... don't put an answer directly . Type a comment and if I will be satisfy I will accept it as answer .
So the question will not be lock for others experts .
0
 
AvonWyssCommented:
If you do know what type the owner is, you can typecast so that you can access the identifiers. Is this what you need?
0
 
ginsonicAuthor Commented:
Can you give me a sample ?

My component ( the owner ) is a TCustomControl descendent .

From TPersistent descendent I wish to call something alike :

FOwner.Prepare;
FOwner.Invalidate;
0
 
DragonSlayerCommented:
umm...

(FOwner as TCustomControl).Invalidate;

I don't think a TCustomControl has a Prepare method... or does it?
0
 
ginsonicAuthor Commented:
Prepare is my own procedure . I need to call Prepare before invalidate .

Nick

BTW, FOwner.Invalidate work too .
0
 
ginsonicAuthor Commented:
No solution here :(
0
 
DragonSlayerCommented:
Do you know the class for the owner? Let's say it is TMyCustomOwnerClass

then all you need to do is TMyCustomOwnerClass(FOwner).Prepare;
0
 
ginsonicAuthor Commented:
Have tried your suggestion :

TDBGrid(FOwner).Prepare; // in my case

No success :(
0
 
DragonSlayerCommented:
but TDBGrid does not have a method called Prepare! where did you declare the Prepare method? Any ideas?
0
 
DragonSlayerCommented:
some codes might be useful
0
 
ginsonicAuthor Commented:
I work to a DBGrid that accept images for background . In same time can be set to transparent or semi-transparent.

Before invalidate my grid, I need to PREPARE ( OWN procedure ) the background ( declared into protected area ).

But in same time , when set couple properties (TPersistent descendents) I need to Invalidate . But before this, still I need to call Prepare . So ...

How can I call from a TPersistent an owner procedure ( OWN declared ) .
0
 
DragonSlayerCommented:
Umm... I need to know who owns Prepare :)
0
 
ginsonicAuthor Commented:
Prepare is a protected procedure of my TgnDBGrid descendent from TCustomDBGrid .

So the owner is TgnDBGrid .
0
 
DragonSlayerCommented:
then you should do

TgnDBGrid(Owner).Prepare;
0
 
ginsonicAuthor Commented:
Already tried :(
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.