[Webinar] Streamline your web hosting managementRegister Today

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 127
  • Last Modified:

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
0
de_ep
Asked:
de_ep
  • 5
  • 4
1 Solution
 
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
[Webinar] Kill tickets & tabs using PowerShell

Are you tired of cycling through the same browser tabs everyday to close the same repetitive tickets? In this webinar JumpCloud will show how you can leverage RESTful APIs to build your own PowerShell modules to kill tickets & tabs using the PowerShell command Invoke-RestMethod.

 
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
 
de_epAuthor Commented:
well sort of ... thanks very much Mike
:Þ de_ep
0

Featured Post

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

  • 5
  • 4
Tackle projects and never again get stuck behind a technical roadblock.
Join Now