Solved

A few questions about TMemo

Posted on 1998-01-06
10
246 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
  • 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
3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

 

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

Netscaler Common Configuration How To guides

If you use NetScaler you will want to see these guides. The NetScaler How To Guides show administrators how to get NetScaler up and configured by providing instructions for common scenarios and some not so common ones.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
How to convert wav to mp3 in delphi 9 200
Delphi TcxGrid group footer summary 3 271
Show Listview image from database (String field) 5 126
can't find the executable in Simulator 1 90
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…
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…
This Micro Tutorial demonstrates using Microsoft Excel pivot tables, how to reverse engineer competitors' marketing strategies through backlinks.
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…

777 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