メモを取るために使用するアウトライナー アプリケーション (Delphi 10.2 Tokyo) があります (これを NoteApp と呼びます)。プレーン テキスト (TextApp) の編集に使用する別のアプリケーションがあります。私はこれらのアプリケーションを頻繁に切り替えるので、メモを取る機能を TextApp に統合することにしました。
コードを NoteApp から TextApp にコピー アンド ペーストし、コンポーネント (1 つの TTreeView、1 つの TRichEdit、および 1 つの TActionToolbar) を TextApp.Form_Main に配置しました。TTreeView の OnCustomDrawItem イベントは、単純なレコードの配列である対応するメモ項目の NoteType に基づいて、各ノードの FontStyle を変更するように設定されます。
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 の上位の項目は問題ありませんが、下に行くほどリフレッシュ レートが低くなります。
すべてのコンポーネントのプロパティは同じように設定されています。私はどこかで間違いを犯したと思います。TextApp の他のすべてのコンポーネントの可視性を false に設定しましたが、TTreeView は依然として非常に遅いです。上記のコードを削除すると、再び高速になります。TextApp ではランタイム テーマを使用しません。