event ...

hi again experts,
i need some suggestion here ...
if i make a component, for example TComponentA, and i have another TComponentB, how can i make my TComponentA can otomatically refresh if TComponentB had changed. of course i can made some code in TComponentB.Onchange, but the problem is how can i made the code in TComponentA, not in TComponentB.

thanks
de_ep
de_epAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

LischkeCommented:
Hi de_ep,

In such cases like yours I use a kind of registration mechanism. TComponentA registers itself with TComponentB. This registration is nothing more than a TList holding the reference to all registered components (if several). If something changes in TComponentB then it just goes through its internal list and calls a method in each registered component. Each of them must have a common method (say HandleChanges) which can be called by TComponentA.

Now, TComponentA (or whatever registered with TComponentB) handles its stuff itself...

Ciao, Mike
0
LischkeCommented:
Opps, little mistake HandleChanges is of course called by TComponentB as it is the component with the change...

Ciao, Mike
0
de_epAuthor Commented:
can i just override some events ??

thanx
de_ep
0
Introducing Cloud Class® training courses

Tech changes fast. You can learn faster. That’s why we’re bringing professional training courses to Experts Exchange. With a subscription, you can access all the Cloud Class® courses to expand your education, prep for certifications, and get top-notch instructions.

LischkeCommented:
Well, then use in OnChange of TComponentB a call to a refresh method in TComponentA. Not very flexible, but should work too.

procedure TComponentB.OnChange;

begin
  FComponentA.HandleChanges;
end;

Is that what you need? And please answer a bit quicker this time since 3 days between each comment will make that we still discuss this question next month ;-)

Ciao, Mike
0
de_epAuthor Commented:
sorry for the delay ... because i've got a very slow connection ... :(

what i need is that i don't need to write any code in TComponentB ... but TComponentA will refresh itself if TComponentB had been changed. i've declared TComponentB in TComponentA.

rgds,
de_ep
0
LischkeCommented:
Well, at least one call to a refresh routine is necessary. How can ComponentA otherwise know that a refresh occured?

On the other hand, there are some things you could do, but I need to know what VCL class is TComponentB is actually derived from... (is it a pure TComponent or a TWinControl?)

Ciao, Mike
0
de_epAuthor Commented:
yup the component is derived from TWinControl, actually i'm gonna make a ComboBox which is like Microsoft Explorer ComboBox, and every time the TreeView refresh, i want it automatically refresh the ComboBox too, without any coding at all in TreeView.Changed, can i just override one of the TreeView events ? i've declare a TreeView in ComboBox's declaration to point to the TreeView, sorry for to much asking, i'm still learning Delhi :)

rgds,
de_ep
0
LischkeCommented:
Right, I think the easiest way is to derive an own tree class and override method Change:

type
  TMyTreeView = class(TTreeView)
  protected
    procedure Change(Node: TTreeNode); override;
  end;

procedure TMyTreeView.Change(Node: TTreeNode);

begin
  inherited;
  TMyComboBox(Owner).DoRefresh;
end;

That should it be. The tree is created with the owner set to the combobox. The combobox needs a method to be called to refresh its content (here I named it DoRefresh).

Hope this is what you are looking for.

Ciao, Mike
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
de_epAuthor Commented:
well sort of ... thanks very much Mike
:Þ de_ep
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Delphi

From novice to tech pro — start learning today.