How can you extract the current line from a TMemo? lazarus / 31-LCL ---------------------------------------------------------------------- vfclists · 2015-05-10 13:25 How can you extract the current line from a TMemo? I want the current line I to be copied whenever I press a particular key, or on some particular event. ---------------------------------------------------------------------- rvk · 2015-05-10 13:33 Your current line would be Memo1.Lines[Memo1.CaretPos.y] ---------------------------------------------------------------------- vfclists · 2015-05-10 19:46 Quote from: rvk on May 10, 2015, 03:33:19 pmYour current line would be Memo1.Lines[Memo1.CaretPos.y] I have tried it and it always returns 0. On checking the source it appears to a virtual method which hasn't been defined ---------------------------------------------------------------------- Cyrax · 2015-05-10 19:57 It works here alright. Lazarus SVN trunk r48926 with FPC trunk 30794. Microsoft Windows Server 2008 R2 with SP1. ---------------------------------------------------------------------- rvk · 2015-05-10 20:05 Quote from: vfclists on May 10, 2015, 09:46:13 pmI have tried it and it always returns 0. On checking the source it appears to a virtual method which hasn't been defined You can't track to that procedure via Lazarus (and find the definition). If you really track the source you get to this point (for Windows): in lcl/interfaces/win32/win32wsstdctrls.pp Code: [Select]class function TWin32WSCustomMemo.GetCaretPos(const ACustomEdit: TCustomEdit): TPoint; var   BufferX: Longword; begin   { X position calculation }   { EM_GETSEL returns the char index of the caret, but this index     doesn't go back to zero in new lines, so we need to subtract     the char index from the line     EM_GETSEL expects a pointer to 32-bits buffer in lParam   }   Windows.SendMessageW(ACustomEdit.Handle, EM_GETSEL, 0, PtrInt(@BufferX));   { EM_LINEINDEX returns the char index of a given line     wParam = -1 indicates the line of the caret   }   Result.X := BufferX - Windows.SendMessageW(ACustomEdit.Handle, EM_LINEINDEX, -1, 0);   { Y position calculation }   { EM_LINEFROMCHAR returns the number of the line of a given     char index.   }   Result.Y := Windows.SendMessageW(ACustomEdit.Handle, EM_LINEFROMCHAR, BufferX, 0); end; Are you using Windows or Linux? ---------------------------------------------------------------------- vfclists · 2015-05-10 22:16 Quote from: rvk on May 10, 2015, 10:05:41 pmQuote from: vfclists on May 10, 2015, 09:46:13 pmI have tried it and it always returns 0. On checking the source it appears to a virtual method which hasn't been defined You can't track to that procedure via Lazarus (and find the definition). If you really track the source you get to this point (for Windows): in lcl/interfaces/win32/win32wsstdctrls.pp ... I am using Qt on Linux. I have switched to TSynMemo, but I am missing wordwrap and simple cat and paste using the right-click menu. ---------------------------------------------------------------------- felipemdc · 2015-05-11 06:00 Quote from: vfclists on May 11, 2015, 12:16:36 amI am using Qt on Linux. Then report a bug that it doesn't work with Qt on Linux. ---------------------------------------------------------------------- zeljko · 2015-05-11 14:02 I've implemented Caret.Y for Qt. Test with r48988 ---------------------------------------------------------------------- vfclists · 2015-05-11 16:19 Quote from: zeljko on May 11, 2015, 04:02:07 pmI've implemented Caret.Y for Qt. Test with r48988 Thanks. I will check it out and try it as soon as I can. ---------------------------------------------------------------------- vfclists · 2015-05-16 13:54 Quote from: zeljko on May 11, 2015, 04:02:07 pmI've implemented Caret.Y for Qt. Test with r48988 Hi, I have tested the fix on r49040 and is working fine. Thanks a lot.