?
Solved

A few questions about TMemo

Posted on 1998-01-06
10
Medium Priority
?
251 Views
Last Modified: 2010-04-04
I have a few questions to ask regarding the TMemo component
1) Is there a way to open large files (>100kb)?
2) How can I get the position of the cursor (i.e. row and col)?
3) Unlike the TRichEdit component, TMemo component does not have the OnSelectionChange event. I need to display the position of the cursor whenever the cursor is moved. How can I do this?

Thanks in Advance
Ermac
0
Comment
Question by:ermac
[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
  • 5
  • 5
10 Comments
 
LVL 8

Accepted Solution

by:
ZifNab earned 400 total points
ID: 1355385
Which version of Delphi are you using?

A1) ? I don't know.

A2) From lloyd's help file :

Q:  How do I know which line number I am currently on in a TMemo?

A:  The trick is to use the em_LineFromChar message.  Try this:

{Note: First line is zero.}
ShowMessage('Line Number: ' + IntToStr(Memo1.Perform(EM_LineFromChar, $FFFF, 0)));

to get row AND col you might do this:

Row := SendMessage(Memo1.Handle, EM_LineFromChar, Memo1.SelStart, 0);
Col := Memo1.SelStart - SendMessage(Memo1.Handle, EM_LineIndex, Row, 0);


Note:  The answer that this gives indicates where the cursor is in the memo field and not where the cursor is in the display of that memo field.  Remember also that the arrays are zero based.  This means that if the cursor is placed before the first character of the first line, that the row and col values will be zero.

A3) You can use the OnkeyDown or OnKeyUp.
    For mouse movements use the mouse events.
0
 

Author Comment

by:ermac
ID: 1355386
Thanks!! It works!
But I got another question to ask...

How do I implement Insert/Overwrite operations using TMemo??
(30 points for this answer)
0
 
LVL 8

Expert Comment

by:ZifNab
ID: 1355387
I'll try to find a solution. : this is already one, but I guess there should be better :

At onkeydown or onkeyup, if Insert key is pushed, toggle a boolean variable between false and true (overwrite and insert)

Check if overwrite is selected :
 if so, first delete character your cursor is on then write the character down. You can put this code in Onkeypress
0
Independent Software Vendors: 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:ermac
ID: 1355388
Have already tried that... However it seems that the Memo flashes a lot when doing this...

Any other solutions??
0
 
LVL 8

Expert Comment

by:ZifNab
ID: 1355389
Still thinking...
0
 

Author Comment

by:ermac
ID: 1355390
Or was it because my code was wrong??
Here's my piece of code for doing it...
with Editor do
begin
  if OverwriteText then
    if (GetTextLen > 0) and (Text[SelStart+1] <> '') and               (Text[SelStart+1] <> #13) then
      SelLength := 1;  
end;
0
 
LVL 8

Expert Comment

by:ZifNab
ID: 1355391
No, looks correct. Maybe with selection lot's of repaint.
Thought otherway, just write VK_DELETE and then character, but
I can't get it to work properly


0
 

Author Comment

by:ermac
ID: 1355392
Have played with the VK_DELETE too...
Could get it to work but it still flashes a lot :(
0
 
LVL 8

Expert Comment

by:ZifNab
ID: 1355393
Sorry, can't find a better solution, maybe there isn't any :-(
Maybe make a new TMemo component?
0
 

Author Comment

by:ermac
ID: 1355394
Anyway thanks for your help! :)
0

Featured Post

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!

Question has a verified solution.

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

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…
In my programming career I have only very rarely run into situations where operator overloading would be of any use in my work.  Normally those situations involved math with either overly large numbers (hundreds of thousands of digits or accuracy re…
In this video, Percona Solutions Engineer Barrett Chambers discusses some of the basic syntax differences between MySQL and MongoDB. To learn more check out our webinar on MongoDB administration for MySQL DBA: https://www.percona.com/resources/we…
How to fix incompatible JVM issue while installing Eclipse While installing Eclipse in windows, got one error like above and unable to proceed with the installation. This video describes how to successfully install Eclipse. How to solve incompa…
Suggested Courses
Course of the Month11 days, 11 hours left to enroll

752 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