Page 1 of 1

Remove "nearest" checkpoint

Posted: Sun Oct 14, 2018 2:17 pm
by Rael Bauer
Hi,

I want to remove the "nearest" checkpoint - meaning the nearest checkpoint going "backwards", but not beyond the current paragraph.

Code: Select all

function TForm1.CheckPointNumber(rve: TCustomRichViewEdit): Integer;
var
  i: Integer;
begin
  Result := -1;
  rve := rve.TopLevelEditor;
  i := rve.CurItemNo;

  while not rve.IsParaStart(i) do
  begin
    if rve.RVData.GetItemCheckpoint(i) <> nil then
    begin
      Result := i;
      exit;
    end;
    dec(i);
  end;

  if rve.RVData.GetItemCheckpoint(i) <> nil then
    Result := i;
end;

Code: Select all

procedure TForm1.miRemoveCheckpointClick(Sender: TObject);
begin
  if Self.CheckPointNumber(rve) > -1 then
  begin
    rve.RemoveCheckpointEd(CheckPointNumber(rve));
    //rve.Invalidate;
  end;
end;
This works for me in a normal document, but does not handle Table cells. How can I also handle table cells with the same logic?

Thanks

Re: Remove "nearest" checkpoint

Posted: Mon Oct 15, 2018 11:46 am
by Sergey Tkachenko
Simply apply this code to TopLevelEditor:

Code: Select all

procedure TForm1.miRemoveCheckpointClick(Sender: TObject);
var
  Editor: TCustomRichViewEdit;
  CPNumber: Integer;
begin
  Editor := rve.TopLevelEditor;
  CPNumber := CheckPointNumber(Editor);
  if CPNumber >= 0 then
    Editor.RemoveCheckpointEd(CPNumber);
end;