<br><br><div class="gmail_quote">On 15 September 2011 15:48, Martin Schreiber <span dir="ltr"><<a href="mailto:mse00000@gmail.com">mse00000@gmail.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin: 0pt 0pt 0pt 0.8ex; border-left: 1px solid rgb(204, 204, 204); padding-left: 1ex;">
<div><div></div><div class="h5">On Thursday 15 September 2011 16:28:29 Frank Church wrote:<br>
> I have a form with some threaded objects that notify another form of events<br>
> by calling one of that forms events.<br>
><br>
> I want to convert to a data module and any interested object to register<br>
> for those notifications.<br>
><br>
> My idea is for each thread to have some kind of list of procedure types and<br>
> each interested object registers its routine eg.<br>
><br>
> This is the data module. It is a rough sketch and may have some syntax<br>
> errors<br>
><br>
> Type TOneArg = Procedure (Var X : integer);<br>
><br>
> > type<br>
> ><br>
> >   TMonitorObject = class(TThread)<br>
> >   private<br>
> ><br>
> >     InterestedObjects: TList<br>
> >     procedure DispatchOutput;<br>
> >     procedure DisplayRawOutput;<br>
> ><br>
> >   protected<br>
> ><br>
> >     procedure Execute; override;<br>
> ><br>
> >   public<br>
> ><br>
> >     constructor Create(CreateSuspended: Boolean);<br>
> >     RegisterInterest(interestedProc:TOneArg);<br>
> ><br>
> >   end;<br>
> ><br>
> > TMonitorObject.RegisterInterest(TOneArg);<br>
> > begin<br>
> ><br>
> >    InterestedObjects.Add(interestedProc);<br>
> ><br>
> > end;<br>
> ><br>
> > procedure TMonitorObject.DispatchOutput;<br>
> > begin<br>
> ><br>
> >    foreach InterestedObject do<br>
> ><br>
> >     InterestedObject.Procedure.Execute;<br>
> ><br>
> > end;<br>
> ><br>
> > constructor TMonitorObject.Create(CreateSuspended: Boolean);<br>
> > begin<br>
> ><br>
> >   inherited Create(CreateSuspended);<br>
> >   InterestedObjects := TList.Create<br>
> >   FCycleComplete := True;<br>
> ><br>
> > end;<br>
><br>
> Do the procedures for the objects which require notification need to be<br>
> constructed in some way?<br>
><br>
</div></div>MSEgui has such a notification mechanism with automatic unlinking by<br>
destroying the objects, see tobjectlinker in lib/common/kernel/mseclasses.pas.<br>
Another possibility is to use a tobjectevent descendant and<br>
application.postevent.<br>
<div class="im"><br>
> Am I on the right track here? I am particularly interested in what happens<br>
> when the objects passing the routines are destroyed without the data module<br>
> knowing about it.<br>
<br>
</div>The program most likely will crash. :-)<br>
<br></blockquote><div><br><br>I want to know if my approach is a workable one and what the right syntax should be, handling the destroyed objects I believe I can deal with by checking for the existence of the object before notifying it.<br>
Are there some examples of that somewhere?<br> <br></div><blockquote class="gmail_quote" style="margin: 0pt 0pt 0pt 0.8ex; border-left: 1px solid rgb(204, 204, 204); padding-left: 1ex;">
Martin<br>
_______________________________________________<br>
fpc-pascal maillist  -  <a href="mailto:fpc-pascal@lists.freepascal.org">fpc-pascal@lists.freepascal.org</a><br>
<a href="http://lists.freepascal.org/mailman/listinfo/fpc-pascal" target="_blank">http://lists.freepascal.org/mailman/listinfo/fpc-pascal</a><br>
</blockquote></div><br><br clear="all"><br>-- <br>Frank Church<br><br>=======================<br><a href="http://devblog.brahmancreations.com">http://devblog.brahmancreations.com</a><br>