Solved

Get 1 line in TRichEdit

Posted on 1998-10-15
14
266 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
  • 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
PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

 

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

PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

Question has a verified solution.

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

Suggested Solutions

A lot of questions regard threads in Delphi.   One of the more specific questions is how to show progress of the thread.   Updating a progressbar from inside a thread is a mistake. A solution to this would be to send a synchronized message to the…
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…
This Micro Tutorial hows how you can integrate  Mac OSX to a Windows Active Directory Domain. Apple has made it easy to allow users to bind their macs to a windows domain with relative ease. The following video show how to bind OSX Mavericks to …
A short tutorial showing how to set up an email signature in Outlook on the Web (previously known as OWA). For free email signatures designs, visit https://www.mail-signatures.com/articles/signature-templates/?sts=6651 If you want to manage em…

803 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