Solved

A few questions about TMemo

Posted on 1998-01-06
10
249 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 100 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
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!

 

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

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Objective: - This article will help user in how to convert their numeric value become words. How to use 1. You can copy this code in your Unit as function 2. than you can perform your function by type this code The Code   (CODE) The Im…
Introduction I have seen many questions in this Delphi topic area where queries in threads are needed or suggested. I know bumped into a similar need. This article will address some of the concepts when dealing with a multithreaded delphi database…
Are you ready to implement Active Directory best practices without reading 300+ pages? You're in luck. In this webinar hosted by Skyport Systems, you gain insight into Microsoft's latest comprehensive guide, with tips on the best and easiest way…

696 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