circular references

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Stephen Robertson

    circular references

    We are currently in a dead end with a circular reference issue using
    vb.net, and are hoping someone might help us resolve it.

    Idea...

    We have frmmain calling frmperson (dim f as new frmperson) in search
    (no record) mode. When the search is executed, frmperson calls
    frmsearchresult (dim f as new frmsearchresult ) which is a listing of
    persons. From frmsearchresult s, frmperson is called (dim f as new
    frmperson) with the resulting record.

    Problem...

    We will get a circular reference between frmperson and
    frmsearchresult .

    I have read the mention of events as a workaround. Could someone
    please elaborate on how the use of events could possibly help us in
    our situation?

    Or, is there another way?

    Thank you very much,

    Dawn Robertson
  • Rob Teixeira [MVP]

    #2
    Re: circular references

    First of all, i'm not really seeing a circular reference here. you have two
    independant instances of frmperson.
    Secondly, what is the problem? Circular references aren't inherantly bad. In
    VB6 there was a problem because COM references aren't cleaned up until the
    ref count for both objects drop (which never happens in a circular
    dependancy unless you resort to some clever tricks), but with a garbage
    collector, as long as both aren't reachable, the GC will still clean them
    up.

    -Rob Teixeira [MVP]

    "Stephen Robertson" <eastforkfarms@ yahoo.com> wrote in message
    news:c362e131.0 407081455.aa030 7@posting.googl e.com...[color=blue]
    > We are currently in a dead end with a circular reference issue using
    > vb.net, and are hoping someone might help us resolve it.
    >
    > Idea...
    >
    > We have frmmain calling frmperson (dim f as new frmperson) in search
    > (no record) mode. When the search is executed, frmperson calls
    > frmsearchresult (dim f as new frmsearchresult ) which is a listing of
    > persons. From frmsearchresult s, frmperson is called (dim f as new
    > frmperson) with the resulting record.
    >
    > Problem...
    >
    > We will get a circular reference between frmperson and
    > frmsearchresult .
    >
    > I have read the mention of events as a workaround. Could someone
    > please elaborate on how the use of events could possibly help us in
    > our situation?
    >
    > Or, is there another way?
    >
    > Thank you very much,
    >
    > Dawn Robertson[/color]


    Comment

    • AlexS

      #3
      Re: circular references

      If you can't compile this project with Visual Studio - try SharpDevelop.
      However, this is not the point of my remark.
      Usually circular references - or perceived as circular - are indicating
      design problems. You can consider for example passing frmsearchresult
      selection (or which frmperson to new) back to original frmperson or its
      parent, which will manage new instance. Maybe person who mentioned events
      meant something like this. You can use events or direct properties for this.
      And several other techniques. In case of events, you can invoke event
      handler when selection changes in frmsearchresult . And handler will be set
      by main controller of your application.
      Would you care to explain more what is the problem? I might miss something.

      HTH
      Alex


      "Stephen Robertson" <eastforkfarms@ yahoo.com> wrote in message
      news:c362e131.0 407081455.aa030 7@posting.googl e.com...[color=blue]
      > We are currently in a dead end with a circular reference issue using
      > vb.net, and are hoping someone might help us resolve it.
      >
      > Idea...
      >
      > We have frmmain calling frmperson (dim f as new frmperson) in search
      > (no record) mode. When the search is executed, frmperson calls
      > frmsearchresult (dim f as new frmsearchresult ) which is a listing of
      > persons. From frmsearchresult s, frmperson is called (dim f as new
      > frmperson) with the resulting record.
      >
      > Problem...
      >
      > We will get a circular reference between frmperson and
      > frmsearchresult .
      >
      > I have read the mention of events as a workaround. Could someone
      > please elaborate on how the use of events could possibly help us in
      > our situation?
      >
      > Or, is there another way?
      >
      > Thank you very much,
      >
      > Dawn Robertson[/color]


      Comment

      • Stephen Robertson

        #4
        Re: circular references

        Rob,

        I agree.

        But, let me explain further. frmperson and frmdsearchresul t are
        individual projects. I have a reference to frmsearchresult in
        frmperson. When I try and set a reference to frmperson in
        frmserachresult , I get the circular reference error.

        The problem is that when I try and set a reference in the
        (frmsearchresul t) project to the project (frmperson)



        "Rob Teixeira [MVP]" <RobTeixeira@@m sn.com> wrote in message news:<eYFnhIUZE HA.3596@tk2msft ngp13.phx.gbl>. ..[color=blue]
        > First of all, i'm not really seeing a circular reference here. you have two
        > independant instances of frmperson.
        > Secondly, what is the problem? Circular references aren't inherantly bad. In
        > VB6 there was a problem because COM references aren't cleaned up until the
        > ref count for both objects drop (which never happens in a circular
        > dependancy unless you resort to some clever tricks), but with a garbage
        > collector, as long as both aren't reachable, the GC will still clean them
        > up.
        >
        > -Rob Teixeira [MVP]
        >
        > "Stephen Robertson" <eastforkfarms@ yahoo.com> wrote in message
        > news:c362e131.0 407081455.aa030 7@posting.googl e.com...[color=green]
        > > We are currently in a dead end with a circular reference issue using
        > > vb.net, and are hoping someone might help us resolve it.
        > >
        > > Idea...
        > >
        > > We have frmmain calling frmperson (dim f as new frmperson) in search
        > > (no record) mode. When the search is executed, frmperson calls
        > > frmsearchresult (dim f as new frmsearchresult ) which is a listing of
        > > persons. From frmsearchresult s, frmperson is called (dim f as new
        > > frmperson) with the resulting record.
        > >
        > > Problem...
        > >
        > > We will get a circular reference between frmperson and
        > > frmsearchresult .
        > >
        > > I have read the mention of events as a workaround. Could someone
        > > please elaborate on how the use of events could possibly help us in
        > > our situation?
        > >
        > > Or, is there another way?
        > >
        > > Thank you very much,
        > >
        > > Dawn Robertson[/color][/color]

        Comment

        • Stephen Robertson

          #5
          Re: circular references

          Alex,

          Thanks for your reply...

          Let me explain further. frmperson and frmdsearchresul t are individual
          projects. I have a reference to frmsearchresult in frmperson. When I
          try and set a reference to frmperson in frmserachresult , I get the
          circular reference error.

          I whould like to keep the (search) frmperson available is the user
          wants to alter the search. This design will allow any number of
          frmperson(searc h) and frmperson(data) and frmsearchresult s to be open
          at anytime.

          I think you are on the right track with the event handlers. If it
          will work, I am just not sure how to implement.



          "AlexS" <salexru2000NO@ SPAMsympaticoPL EASE.ca> wrote in message news:<uzmCYXUZE HA.644@tk2msftn gp13.phx.gbl>.. .[color=blue]
          > If you can't compile this project with Visual Studio - try SharpDevelop.
          > However, this is not the point of my remark.
          > Usually circular references - or perceived as circular - are indicating
          > design problems. You can consider for example passing frmsearchresult
          > selection (or which frmperson to new) back to original frmperson or its
          > parent, which will manage new instance. Maybe person who mentioned events
          > meant something like this. You can use events or direct properties for this.
          > And several other techniques. In case of events, you can invoke event
          > handler when selection changes in frmsearchresult . And handler will be set
          > by main controller of your application.
          > Would you care to explain more what is the problem? I might miss something.
          >
          > HTH
          > Alex
          >
          >
          > "Stephen Robertson" <eastforkfarms@ yahoo.com> wrote in message
          > news:c362e131.0 407081455.aa030 7@posting.googl e.com...[color=green]
          > > We are currently in a dead end with a circular reference issue using
          > > vb.net, and are hoping someone might help us resolve it.
          > >
          > > Idea...
          > >
          > > We have frmmain calling frmperson (dim f as new frmperson) in search
          > > (no record) mode. When the search is executed, frmperson calls
          > > frmsearchresult (dim f as new frmsearchresult ) which is a listing of
          > > persons. From frmsearchresult s, frmperson is called (dim f as new
          > > frmperson) with the resulting record.
          > >
          > > Problem...
          > >
          > > We will get a circular reference between frmperson and
          > > frmsearchresult .
          > >
          > > I have read the mention of events as a workaround. Could someone
          > > please elaborate on how the use of events could possibly help us in
          > > our situation?
          > >
          > > Or, is there another way?
          > >
          > > Thank you very much,
          > >
          > > Dawn Robertson[/color][/color]

          Comment

          • AlexS

            #6
            Re: circular references

            Do you need to reference frmperson from frmsearchresult ?
            If search is done from frmperson, you can show frmsearchresult and get
            selection from there. Suppose, you have button on frmsearchresult , which
            must show new frmperson. If you want to leave frmsearchresult on screen and
            show new frmperson at the same time, you can inform main frmperson that new
            one should be created by setting button click event handler to method in
            frmperson:

            frmperson code:
            ....
            frmsearchresult fs = new frmsearchresult (...);
            fs.ShowSelected PersonButton.Cl ick += new
            EventHandler(th is.ShowNewPerso nUsingSearchRes ult);
            fs.Show();
            ....

            In the event handler you can use some property or method in frmsearchresult
            to get person id or whatever you use to init frmPerson.
            I see no need to make circular reference in this case.
            You might want to check also Observer pattern if you want to implement more
            complex scheme of interaction:


            HTH
            Alex

            "Stephen Robertson" <eastforkfarms@ yahoo.com> wrote in message
            news:c362e131.0 407090404.6db52 2f9@posting.goo gle.com...[color=blue]
            > Alex,
            >
            > Thanks for your reply...
            >
            > Let me explain further. frmperson and frmdsearchresul t are individual
            > projects. I have a reference to frmsearchresult in frmperson. When I
            > try and set a reference to frmperson in frmserachresult , I get the
            > circular reference error.
            >
            > I whould like to keep the (search) frmperson available is the user
            > wants to alter the search. This design will allow any number of
            > frmperson(searc h) and frmperson(data) and frmsearchresult s to be open
            > at anytime.
            >
            > I think you are on the right track with the event handlers. If it
            > will work, I am just not sure how to implement.
            >
            >
            >
            > "AlexS" <salexru2000NO@ SPAMsympaticoPL EASE.ca> wrote in message[/color]
            news:<uzmCYXUZE HA.644@tk2msftn gp13.phx.gbl>.. .[color=blue][color=green]
            > > If you can't compile this project with Visual Studio - try SharpDevelop.
            > > However, this is not the point of my remark.
            > > Usually circular references - or perceived as circular - are indicating
            > > design problems. You can consider for example passing frmsearchresult
            > > selection (or which frmperson to new) back to original frmperson or its
            > > parent, which will manage new instance. Maybe person who mentioned[/color][/color]
            events[color=blue][color=green]
            > > meant something like this. You can use events or direct properties for[/color][/color]
            this.[color=blue][color=green]
            > > And several other techniques. In case of events, you can invoke event
            > > handler when selection changes in frmsearchresult . And handler will be[/color][/color]
            set[color=blue][color=green]
            > > by main controller of your application.
            > > Would you care to explain more what is the problem? I might miss[/color][/color]
            something.[color=blue][color=green]
            > >
            > > HTH
            > > Alex
            > >
            > >
            > > "Stephen Robertson" <eastforkfarms@ yahoo.com> wrote in message
            > > news:c362e131.0 407081455.aa030 7@posting.googl e.com...[color=darkred]
            > > > We are currently in a dead end with a circular reference issue using
            > > > vb.net, and are hoping someone might help us resolve it.
            > > >
            > > > Idea...
            > > >
            > > > We have frmmain calling frmperson (dim f as new frmperson) in search
            > > > (no record) mode. When the search is executed, frmperson calls
            > > > frmsearchresult (dim f as new frmsearchresult ) which is a listing of
            > > > persons. From frmsearchresult s, frmperson is called (dim f as new
            > > > frmperson) with the resulting record.
            > > >
            > > > Problem...
            > > >
            > > > We will get a circular reference between frmperson and
            > > > frmsearchresult .
            > > >
            > > > I have read the mention of events as a workaround. Could someone
            > > > please elaborate on how the use of events could possibly help us in
            > > > our situation?
            > > >
            > > > Or, is there another way?
            > > >
            > > > Thank you very much,
            > > >
            > > > Dawn Robertson[/color][/color][/color]


            Comment

            • Phill.  W

              #7
              Re: circular references

              "Stephen Robertson" <eastforkfarms@ yahoo.com> wrote in message
              news:c362e131.0 407081455.aa030 7@posting.googl e.com...
              .. . .[color=blue]
              > We have frmmain calling frmperson (dim f as new frmperson) in
              > search (no record) mode. When the search is executed, frmperson
              > calls frmsearchresult (dim f as new frmsearchresult ) which is a listing
              > of persons. From frmsearchresult s, frmperson is called (dim f as new
              > frmperson) with the resulting record.[/color]

              Would it not be better to pass frmSearchResult a reference to the
              existing frmPerson form (object), and allow the results for to reuse this,
              rather than creating a new form every time, as in

              [frmPerson]
              Sub DoSearch( ... ) Handles ...
              Dim oSearch as New frmSearchResult
              oSearch.Display Using = Me
              oSearch.Show[Dialog]()
              End Sub

              [frmSearchResult]

              ' ONLY as an example
              Public DisplayUsing as frmPerson = Nothing

              Sub RowSelected() Handles ...
              If ( Me.DisplayUsing is Nothing ) Then
              Me.DisplayUsing = New frmPerson
              End If
              Me.DisplayUsing .Show()
              . . .
              End Sub

              HTH,
              Phill W.


              Comment

              Working...