1
我有一個名爲dbmemSummary的DBMemo和一個方法ReplaceLineBreaks,它將從數據庫備註中刪除多餘的換行符。我面臨着設置光標位置的問題。如何在替換換行符後在Delphi中保持遊標位置
這是方法片段 -
procedure ReplaceLineBreaks;
var
Save_Cursor: TCursor;
aOldTextList: TStringList;
aNewTextList: TStringList;
i, : Integer;
begin
inherited;
aOldTextList := TStringList.Create;
aNewTextList := TStringList.Create;
try
Save_Cursor := Screen.Cursor;
aOldTextList.text := dbmemDisciplineSummary.text;
for i := 0 to aOldTextList.Count - 1 do begin
if (i = 0) and(Trim(aOldTextList[i]) <> '') then
aNewTextList.Add(aOldCN_TextList[i])
else if not ((i<>0) and (Trim(aOldTextList[i - 1]) = '') and (Trim(aOldTextList[i]) = '')) then
aNewTextList.Add(aOldTextList[i]);
end;
cdsPTClinicalNotesCNTEXT.AsString := aNewTextList.Text;
finally
Screen.Cursor := Save_Cursor;
FreeAndNil(aOldTextList);
FreeAndNil(aNewTextList);
end;
end;
但它不設置光標回到同一位置......有一個人,請幫助?
TCursor是鼠標指針,而不是備忘錄插入符號,其中一些人稱之爲光標。您需要查看便條位置的備忘SelStart屬性。你需要跟蹤,當你刪除線。就我個人而言,我將使用拆分備忘錄文本到selstart位置的左側和右側,並分別用StringReplace刪除行。 – MikeD