• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 278
  • Last Modified:

Get 1 line in TRichEdit

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
stinger_60284
Asked:
stinger_60284
  • 6
  • 4
  • 4
1 Solution
 
rwilson032697Commented:
Use the lines property in the TRichEdit control
0
 
viktornetCommented:
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
 
stinger_60284Author Commented:
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
Cloud Class® Course: Microsoft Exchange Server

The MCTS: Microsoft Exchange Server 2010 certification validates your skills in supporting the maintenance and administration of the Exchange servers in an enterprise environment. Learn everything you need to know with this course.

 
stinger_60284Author Commented:
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
 
rwilson032697Commented:
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
 
viktornetCommented:
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
 
stinger_60284Author Commented:
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
 
viktornetCommented:
Don't know what ya talk'n 'bout....... You can't detect the arrow keys I guess....

Regards,
Viktor Ivanov
0
 
rwilson032697Commented:
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
 
viktornetCommented:
Oh, is that what he wanted..... o O If that is it, then rwilson is right,,, Talk to ya L8R

Cheers,
Viktor
0
 
viktornetCommented:
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
 
rwilson032697Commented:
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
 
viktornetCommented:
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
 
stinger_60284Author Commented:
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
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Cloud Class® Course: Certified Penetration Testing

This CPTE Certified Penetration Testing Engineer course covers everything you need to know about becoming a Certified Penetration Testing Engineer. Career Path: Professional roles include Ethical Hackers, Security Consultants, System Administrators, and Chief Security Officers.

  • 6
  • 4
  • 4
Tackle projects and never again get stuck behind a technical roadblock.
Join Now