Solved

Get 1 line in TRichEdit

Posted on 1998-10-15
14
271 Views
Last Modified: 2010-04-06
How to get 1 line in TRichEdit whether worwrap flag is set true
for false?
For example:
   +---------------------------------+
   | I love to program in Delphi     |
   | And I love Experts-Exchange too |
   +---------------------------------+
This is when wordwrap is set to false, and I want to get, for
example: "I love to program in Delphi", and store it to a
string variable.
But if wordwrap is set to true, then it can be like this:
   +----------------------+
   | I love to program in |
   | Delphi               |
   | And I love           |
   | Experts-Exchange too |
   +----------------------+
And I still want to get "I love to program in Delphi".
If wordwrap is set to true, then I think, soft return will be
activated. Yet I still want to consider it as one line.
Hope you can understand what I want, and I need explanation
in Delphi source code.
I use Delphi 3, so please keep the source code work in Delphi 3.

Thanks anyway for the help and attention ^_^

Stinger

0
Comment
Question by:stinger_60284
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 6
  • 4
  • 4
14 Comments
 
LVL 12

Accepted Solution

by:
rwilson032697 earned 100 total points
ID: 1343089
Use the lines property in the TRichEdit control
0
 
LVL 10

Expert Comment

by:viktornet
ID: 1343090
You could do this...
var
  Str : string;
begin
  //You could also check if the WordWrap is set to true or not and then proceed
  RichEdit1.WordWrap := False;
  str := RichEdit1.Lines[0];
  Caption := str; //Just an example to display it on the form's caption
  RichEdit1.WordWrap := True; //Set it back to true
end;

Regards,
Viktor Ivanov
0
 

Author Comment

by:stinger_60284
ID: 1343091
Is that as simple as that?
Okay, I mean I want to get the line in the cursor position where user can point it anywhere. So, how to detect it?

0
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

Author Comment

by:stinger_60284
ID: 1343092
Is that as simple as that?
Okay, I mean I want to get the line in the cursor position where user can point it anywhere. So, how to detect it?

0
 
LVL 12

Expert Comment

by:rwilson032697
ID: 1343093
Stinger,

To do that you can get the cusor position with SelStart (the position of the cursor with respect to the Text property) then move backwards through Text until you find a new line, then forwards through Text until you find a new line then copy out that section which should give what you want.

Cheers,

Raymond.
0
 
LVL 10

Expert Comment

by:viktornet
ID: 1343094
Hello stinger!

This one is suppose to be working even though I haven't tested it.. Please try it out and tell me what the results are! Here is the code...

var
  i, OldStart : integer;
  Str : string;
begin
  Str := '';
  with Memo1 do begin
    OldStart := SelStart;
    i := Perform(EM_LINEFROMCHAR, SelStart, 0);
    if WordWrap = True then begin
      WordWrap := False;
      Str := Lines[i];
      WordWrap := True;
    end else
      Str := Lines[i];
    Caption := Str; //Just an example
    SelStart := OldStart;
  end;
end;

Hope this helps!

Regards,
Viktor Ivanov
0
 

Author Comment

by:stinger_60284
ID: 1343095
Okay, I'll increase the point, because there is a question
in my mind. Sorry for not grading you yet... :)
This is my question (still related with Line in TRichEdit):
If I detect key arrow down (#80), the cursor will be pointed
to the next line (whether it's wordwrap or not).
If I detect key arrow up (#72), the cursor will be pointed to
the previous line(whether it's wordwrap or not).
The question is how to do it? I can't use readkey to detect
key down and key up, like in Turbo Pascal.

Once again, I really need the help and thanks for your
guidance to this Delphi's Newbie
:)

Regards

Stinger
0
 
LVL 10

Expert Comment

by:viktornet
ID: 1343096
Don't know what ya talk'n 'bout....... You can't detect the arrow keys I guess....

Regards,
Viktor Ivanov
0
 
LVL 12

Expert Comment

by:rwilson032697
ID: 1343097
Viktor: The EM_LINEFROMCHAR message is a much better way than scanning the line!

Stinger: What you need to do is create your own TRichEdit descendent and override the WMCHAR method. In the overridden method you can than check if it is an arrow and do want you need to do. Remember to call the inherited method:

type
  TMyRichEdit = class(TRichEdit)
    protected
      procedure WMCHAR(var Message : TWMChar); Override; // I'm not sure if the override is needed...
  end;

.

Procedure TMyRichEdit.WMChar(var Message : TWMChar);

begin
  if Message.CharCode = VK_UP then
. // You get the picture


  Inherited;
end;
0
 
LVL 10

Expert Comment

by:viktornet
ID: 1343098
Oh, is that what he wanted..... o O If that is it, then rwilson is right,,, Talk to ya L8R

Cheers,
Viktor
0
 
LVL 10

Expert Comment

by:viktornet
ID: 1343099
Hi again!
>procedure WMCHAR(var Message : TWMChar); Override; // I'm not
>     sure if the override is needed...
This one would be as follows....
procedure WMCHAR(var Message : TWMChar);message WM_CHAR;

Regards,
Viktor Ivanov
0
 
LVL 12

Expert Comment

by:rwilson032697
ID: 1343100
You are right again Viktor!

The reason I was unsure is I thought these things automatically override, which they do by specifying the message it maps to!

0
 
LVL 10

Expert Comment

by:viktornet
ID: 1343101
If you just need this for only one use you could do this w/o creating a new components like this///
In OnKeyDown() of the control
procedure TForm1.WhateverKeyDown({...});
begin
  case Key of
    VK_RIGHT  : //Right arrow key
    VK_LEFT    : //Left arrow key
    VK_UP        : //Up arrow key
    VK_DOWN : //Down arrow key
  end;
end;

Regards,
Viktor Ivanov
0
 

Author Comment

by:stinger_60284
ID: 1343102
Wow!!! Okay, there are so many experts who are very kindly
help me. Thank for all of you!!!
Without you, I can't do this.

Once again, thanks
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article explains how to create forms/units independent of other forms/units object names in a delphi project. Have you ever created a form for user input in a Delphi project and then had the need to have that same form in a other Delphi proj…
Creating an auto free TStringList The TStringList is a basic and frequently used object in Delphi. On many occasions, you may want to create a temporary list, process some items in the list and be done with the list. In such cases, you have to…
In this video, viewers will be given step by step instructions on adjusting mouse, pointer and cursor visibility in Microsoft Windows 10. The video seeks to educate those who are struggling with the new Windows 10 Graphical User Interface. Change Cu…
In this video we outline the Physical Segments view of NetCrunch network monitor. By following this brief how-to video, you will be able to learn how NetCrunch visualizes your network, how granular is the information collected, as well as where to f…

707 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question