我有一个大纲应用程序(在 Delphi 10.2 Tokyo 中),用于记笔记(我称之为 NoteApp)。我有另一个用于编辑纯文本 (TextApp) 的应用程序。由于我经常在这些应用程序之间切换,我决定在 TextApp 中集成笔记功能。
我将代码从 NoteApp 复制/粘贴到 TextApp,并将组件(一个 TTreeView、一个 TRichEdit 和一个 TActionToolbar)放在 TextApp.Form_Main 上。TTreeView 的 OnCustomDrawItem 事件设置为根据对应的注释项的 NoteType 更改每个 Node 的 FontStyle,NoteType 是一个简单记录的数组:
type
///
/// Note types
///
TNoteType = (ntNote, ntTodo, ntDone, ntNext, ntTitle) ;
///
///
///
TNote = Record
Text ,
Attachment ,
Properties ,
CloseDate : String ;
NoteType : TNoteType ;
End;
我们的数组:
var
Notes: Array of TNote ;
和事件:
procedure TForm_Main.TreeView_NotesCustomDrawItem(Sender: TCustomTreeView;
Node: TTreeNode; State: TCustomDrawState; var DefaultDraw: Boolean);
begin
///
/// First check to see if the application allows us to change visuals. If the
/// application is in processing mode, visual updates are not allowed.
///
if ChangeAllowed AND Node.IsVisible then
begin
///
/// Check NoteType of the corresponding note:
///
case Notes[Node.AbsoluteIndex].NoteType of
ntTitle:
begin
TreeView_Notes.Canvas.Font.Style := [fsBold] ;
end;
//ntNote:
// begin
// end;
ntTodo:
begin
TreeView_Notes.Canvas.Font.Style := [fsBold] ;
end;
ntNext:
begin
TreeView_Notes.Canvas.Font.Style := [fsUnderline] ;
end;
ntDone:
begin
TreeView_Notes.Canvas.Font.Style := [fsStrikeOut] ;
end;
end;
end;
end;
当我在 NoteApp 中打开一个便笺文件时,它运行良好。当我在 TextApp 中打开同一个文件时,TTreeView 刷新缓慢。TTreeView 中的 top 项是可以的,但是越往下,刷新率越低。
所有组件的属性设置相同。我怀疑我在某个地方犯了错误。我将 TextApp 上所有其他组件的可见性设置为 false,但 TTreeView 仍然非常缓慢。如果我删除上面的代码,它会再次变快。我不在 TextApp 中使用运行时主题。