Captain Harville is distressed in Chapter 23 of Persuasion because of Captain Benwick's change of affections from Miss Fanny Harville to Louisa. In this state, he invites Anne to stand beside him at the edge of the Musgrove's room next to the window so he can confide his thoughts to her.
Harville laments that Captain Benwick has so soon forgotten Fanny and turned his affections to Louisa, being thrown together with her after her fall. Harville says to Anne: "Poor Fanny! she would not have forgotten him so soon!" Thus he introduces a long discussion between the two of them about the question of whether men or women are constant in their affections for the objects of their love when parted from them.
Captain Wentworth is seated at a writing desk near at hand engaged in writing a letter about the miniature portrait of Captain Benewick that Benwick has asked Harville to give to Louisa (though it had been produced in Cape Town, South Africa, for Fanny Harville). Wentworth is near enough so that, if he tries, he can hear what Anne and Harville are speaking of.
He hears that Harville wins the point that men feel a deep and abiding constancy of love and affection when separated from their wives and families. He also hears that Anne wins the point that women feel constancy of love and affection more deeply and for longer than men when the object of their love is removed from them either through death or other circumstances:
[Anne}: No, I believe [men] capable of everything great and good in your married lives. ... while the woman you love lives, and lives for you. All the privilege I claim for my own sex ... is that of loving longest, when existence or when hope is gone.
The importance of this is that Wentworth here learns indirectly that Anne still loves him and has always loved him and that therefore there may be renewed hope for him for winning her hand in marriage. The result of this learning is that while under the pretense of finishing his letter written on Benwick's behalf, he hastily pens another letter addressed to Anne confessing his feelings and his hopes.
Too good, too excellent creature! You do us justice, indeed. You do believe that there is true attachment and constancy among men. Believe it to be most fervent, most undeviating, in F. W.
He then contrives a way to secretly hand it to her. Anne reads his letter and brings herself to believe that he still loves her and is seeking her love again as she learns from the letter that hope has been renewed in his heart.
[Wentworth]: Tell me not that I am too late, that such precious feelings are gone for ever. I offer myself to you again with a heart even more your own than when you almost broke it, ....
The result of this learning is that Anne and Wentworth finally reach an agreement and finally have the freedom to unite their love in marriage, a marriage that makes all of Anne's well-wishers happy--eventually:
There was nothing less for Lady Russell to do, than to admit that she had been pretty completely wrong, and to take up a new set of opinions and of hopes.