Select a whole line in TSynEdit, TMemo or TRichEdit

Please discuss general Delphi programming topics here.

Select a whole line in TSynEdit, TMemo or TRichEdit

Postby m_b » August 4th, 2004, 2:03 pm

How can I select a whole line in TSynEdit, TMemo or TRichEdit if I've got it's index?
I know that I can use the SelStart and SelLength, but when I do that if the line is longer than the component width - the component scrolls to the end of the line, and this is really annoying to the user - he has to scroll back, what I want is to select the whole line without scrolling to the end of it. So, any suggestions???

m_b
m_b
Active Member
Active Member
 
Posts: 18
Joined: June 23rd, 2004, 10:19 am

Postby Kambiz » August 4th, 2004, 3:09 pm

The following code may help you.

Code: Select all
function SelectLine(EditHandle: THandle; LineIndex: Integer; CaretInView: Boolean): Boolean;
var
  LineStart: Integer;
  LineLength: Integer;
begin
  Result := False;
  LineStart := SendMessage(EditHandle, EM_LINEINDEX, LineIndex, 0);
  if LineStart >= 0 then
  begin
    LineLength := SendMessage(EditHandle, EM_LINELENGTH, LineStart, 0);
    SendMessage(EditHandle, EM_SETSEL, LineStart, LineStart + LineLength);
    if CaretInView then SendMessage(EditHandle, EM_SCROLLCARET, 0, 0);
    Result := True;
  end;
end;

procedure TForm1.Button1Click(Sender: TObject);
begin
  if not SelectLine(Memo1.Handle, SpinEdit1.Value, False) then
    ShowMessage('Line index out of bounds');
end;
User avatar
Kambiz
Administrator
Administrator
 
Posts: 2429
Joined: March 7th, 2003, 7:10 pm

Postby m_b » August 5th, 2004, 11:07 am

I'm sorry Kambiz, but this function does nothing, I've tried it with SynEdit and Memo, and nothing gets selected... Is there another way?
m_b
Active Member
Active Member
 
Posts: 18
Joined: June 23rd, 2004, 10:19 am

Postby Kambiz » August 5th, 2004, 11:34 am

I have no idea about SynEdit, but I'm sure the function works for TMemo and TRichEdit.

Maybe the HideSelection property of the memo is True, and you don't see the selection.
User avatar
Kambiz
Administrator
Administrator
 
Posts: 2429
Joined: March 7th, 2003, 7:10 pm

Postby m_b » August 5th, 2004, 4:18 pm

You know, that may be possible, I'll check that and let you know if it worked...
m_b
Active Member
Active Member
 
Posts: 18
Joined: June 23rd, 2004, 10:19 am

Postby m_b » August 8th, 2004, 2:35 pm

Yep, it works with memo & richedit, but not in synedit... Does anyone know how to get it to work with synedit?
m_b
Active Member
Active Member
 
Posts: 18
Joined: June 23rd, 2004, 10:19 am


Return to Delphi Programming

Who is online

Users browsing this forum: No registered users and 2 guests

cron