Solved

Get 1 line in TRichEdit

Posted on 1998-10-15
14
263 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
 

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
Find Ransomware Secrets With All-Source Analysis

Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

 
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

Free Trending Threat Insights Every Day

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

In this tutorial I will show you how to use the Windows Speech API in Delphi. I will only cover basic functions such as text to speech and controlling the speed of the speech. SAPI Installation First you need to install the SAPI type library, th…
Have you ever had your Delphi form/application just hanging while waiting for data to load? This is the article to read if you want to learn some things about adding threads for data loading in the background. First, I'll setup a general applica…
This demo shows you how to set up the containerized NetScaler CPX with NetScaler Management and Analytics System in a non-routable Mesos/Marathon environment for use with Micro-Services applications.
This video demonstrates how to create an example email signature rule for a department in a company using CodeTwo Exchange Rules. The signature will be inserted beneath users' latest emails in conversations and will be displayed in users' Sent Items…

744 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

Need Help in Real-Time?

Connect with top rated Experts

9 Experts available now in Live!

Get 1:1 Help Now