I have a component that draws a graph from a table similar to a spreadsheet. In the graph component, I have a TRect that describes the viewport of the graph. I want to draw a vertical line on the graph when a user clicks on a cell of the table. I am able to draw the graph and the associated line, but when I click on another cell the first line is still there after the second line is drawn. I have tried all of the Canvas.Pen.Mode choices and each has something left. I think I want to make a copy of the original graph before any lines are drawn and copy this image back and then draw the line. How can I do that? I have looked at TBitMap, but am not clear how to use this.

I want to draw a vertical line on the graph when a user clicks on a
cell of the table. I am able to draw the graph and the associated
line, but when I click on another cell the first line is still there after
the second line is drawn.

That implies that you are maintaining a persistent drawing of the graph and
you are drawing the lines on that image. Don't do that. Since the lines
are dynamic, draw them dynamically only when they are actually needed.

I think I want to make a copy of the original graph before any lines
are drawn and copy this image back and then draw the line. How
can I do that?

That is overkill, you don't need to do it that way. Simply keep track of
which cell was last clicked on, and make sure each click calls the the component's
Invalidate() method after updating that tracking info. Then, whenever the
component is painted, first draw the main graph onto the component, then
draw the current line on top of that drawing if a cell has been clicked.

If you need help with that, please show your current component code, and
someone can show you how to insert the extra logic.

Here is the code that works: Data1 is the spreadsheet component, and of course DeltaGraph1 is the graph.
In the table cell click: Notice that I turn off the old line, then redraw the graph and finally draw the new line.
procedure TForm1.Data1Click(Sender: TObject);
begin
if TurnOnOffGrp.ItemIndex=0 then
begin
if (OldCl>=0) and (OldRw>=0) then
begin
with DeltaGraph1 do
DeltaGraph1.TurnOffLastLine(OldCol, OldRow); // if I only turn off the line and don’t redraw the graph, there is a gap where the line was taken out.
end;
DeltaGraph1.DrawGraph; // have to redraw the graph to eliminate the gap.
DeltaGraph1.DrawVertLine(Data1.Col,Data1.Row);
OldCl:=Data1.Col;
OldRw:=Data1.Row;
end;
end;