Just be there: listen and make them feel that you understand their feelings and that you won't abandon them. No use pointing out that there's worse luck in the world - they know that and don't need to hear it. After some time you could make a cup of tea or do some of the chores they're not yet up to. Just be patient and think of what you would need yourself in such a situation; it gives you the clues for your actions.
Just be there for them. If they want to talk about their loss, tell them the person they loved will live forever in their hearts and in their memories.
Currently a close relative of mine is dying from pancreatic cancer. The person in question was raised atheist, but in recent years has drifted back towards organized religion, at least for purposes of social interaction and community support. Such things occasionally happen in life's twilight.
Rather than to attack religion or seek smarmy platitudes, my approach has been to describe that all life is finite and all life is fraught with struggle, with pain and misunderstanding, with self-deception and (however innocent or unwitting) the deception of others. Pain is never good, but the cessation of life is also the cessation of pain. Especially if a person is old and has lived through much, has overcome much adversity and with good conscience can claim to have accomplished significant things, then death is not a case of being snatched away too soon, but of well-deserved rest. To die is not to abandon one's family but to unburden oneself of trappings and tensions that have been so dominant for so long. While we live, we should do our best to live sincerely and to minimize whatever suffering we can. In impending death, it is our turn to see our suffering minimized, and we should welcome the conclusion as not only the inevitable finality but as something towards which we have been working.
Memory is also finite. The greatest authors, thinkers, artists, scientists, doers - the ones whose memory supposedly lives on over the centuries - are really also forgotten as persons. At best we remember their most memorable quotes. Philosophy essentially begins with Plato, and philosophers consult written records of his discourses daily. But who was he? Do we really know? And do we really care? What, then, about the memory of "regular people", the mothers and grandfathers and uncles and neighbors, the college roommates and office coworkers, who wrote nothing and coined no pithy expressions, proved no theorems and designed no skyscrapers? Yes, we think fondly of them for a while, but eventually we too shall die, and our memories become corrupted and stunted over the succeeding generations. This is wistfully regrettable in the abstract, but in the concrete it is only natural. All life is finite, even in memory. And even though we delude ourselves, we would not be fools by considering the finitude to make the memory all the sweeter.