I have a context panel in my form which will display properties of the current item. I found there is not OnItemChanged(ItemStyle) event, so I've handled the OnCaretMoved and check curItemStyle to update my UI context panel accordingly. I got an AV too and from your explanation the AV is caused by GetCurrentItemEx where it tries to access an unformatted doc.
Code: Select all
procedure OnCaretMoved;
var
nLine, nColumn, nListIndex, nItemStyle: Integer;
rveTemp: TCustomRichViewEdit;
function IsCaretInTableCell: Boolean;
var
rveTable: TCustomRichViewEdit;
rveTableItemInfo: TCustomRVItemInfo;
begin
Result := RichViewEdit1.GetCurrentItemEx(TRVTableItemInfo, rveTable, rveTableItemInfo);
end;
begin
rveTemp := RichViewEdit1.TopLevelEditor;
with rveTemp do
begin
nItemStyle := rveTemp.GetItemStyle(rveTemp.CurItemNo);
if nItemStyle < 0 then
begin
case nItemStyle of
rvsPicture, rvsHotPicture: Caption := 'Now Picture';
else
begin
if IsCaretInTableCell then
Caption := 'Now Table'
else
Caption := 'Now Normal';
end;
end;
end
else
begin
if IsCaretInTableCell then
Caption := 'Now Table'
else
Caption := 'Now Normal';
end;
end;
end;
Then from your suggestion, I have move this part of code to OnSelect, it works fine, but there is a case where this event will not be triggered which is, use your mouse to click a picture in the content, then press -> in your keyboard, then start typing, this event is not triggered so I have no way of knowing current the caret is no longer in a picture so that I can hide my picture context panel.
For this type of context showing, any better event to handle? Thanks.