Solved

A few questions about TMemo

Posted on 1998-01-06
10
240 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
 

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
IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

 

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

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Suggested Solutions

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…
Introduction Raise your hands if you were as upset with FireMonkey as I was when I discovered that there was no TListview.  I use TListView in almost all of my applications I've written, and I was not going to compromise by resorting to TStringGrid…
This video discusses moving either the default database or any database to a new volume.
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.

758 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

21 Experts available now in Live!

Get 1:1 Help Now