Solved

how to lock mouse in TMemo ?

Posted on 1998-08-02
19
283 Views
Last Modified: 2011-09-20
Hi experts,

with the help of a TMemo component, I display the content of an ASCII text file.
As I desire it, I can not edit and change the displayed text. However, unfortunately,
it is still possible to mark the text with the mouse cursor.
How can I avoid this manipulation within the TMemo element?

With kind regards

Christian

0
Comment
Question by:mathes
  • 7
  • 7
  • 5
19 Comments
 
LVL 10

Expert Comment

by:viktornet
ID: 1359454
You mean you want to disable the user of highlighting, and editing the text? If that's your question, then here is something you might try.

if you have other controls on the form then you can write in OnEnter of the memo....
NameOfControl.SetFocus;

You can also use HideCaret(Memo1.Handle);...but as soon as you set the focus on other control and come back to the memo it shows up again, so there is a problem. You can also try DestroyCaret;

Regards,
Viktor Ivanov


0
 
LVL 3

Expert Comment

by:Matvey
ID: 1359455
Hi guys. Do this, and the memo is totally paralised with mouseclicks and keydowns. Didn't find anything better:

type
  TNoSelMemo = class(TMemo)
  protected
    procedure WMLButtonDown(var Message: TWMLButtonDown); message WM_LBUTTONDOWN;
    procedure WMRButtonDown(var Message: TWMRButtonDown); message WM_RBUTTONDOWN;
    procedure WMLButtonDblClk(var Message: TWMLButtonDown); message WM_LBUTTONDBLCLK;
    procedure WMKeyDown(var Message: TWMKeyDown); message WM_KEYDOWN;
  end;


procedure TNoSelMemo.WMLButtonDown(var Message: TWMLButtonDown);
begin Message.Result := 0 end;

procedure TNoSelMemo.WMRButtonDown(var Message: TWMRButtonDown);
begin Message.Result := 0 end;

procedure TNoSelMemo.WMLButtonDblClk(var Message: TWMLButtonDown);
begin Message.Result := 0 end;

procedure TNoSelMemo.WMKeyDown(var Message: TWMKeyDown);
begin Message.Result := 0 end;


Then use TNoSelMemo instead of the regular TMemo.
Good luck, Matvey
0
 

Author Comment

by:mathes
ID: 1359456

Dear Victor,

thank you for comment,

> You mean you want to disable the user of highlighting, and editing the
> text? If that's your question,

Yes, this is exactly what I would like to achieve.
 then

> if you have other controls on the form then you can write in OnEnter
>of the memo....
>
>NameOfControl.SetFocus;

Yes, I have another control on my form and I like your idea with the
SetFocus very much. I have a command button which has the name:
"EndFileViewer".

However  I am faced with one problem.

When I go to the events and change the properties of Memo1:TMemo,

to: "EndFileViewer.SetFocus (without the "")


Delphi complains that "EndFileViewer.SetFocus" is not a valid identifier.

What am I doing wrong here.

Regards,
Christian


0
 
LVL 3

Expert Comment

by:Matvey
ID: 1359457
If you want to get a control focused you just call <control_name>.Setfocus;

In your case - EndFileViewer.SetFocus;

Vik, I'm not sure that's a good idea though. If the user wants to scroll the text, he might be unable to do it.

mathes, no comments for me at all? :-)
0
 

Author Comment

by:mathes
ID: 1359458

Dear Matvey,

>If you want to get a control focused you just call
> <control_name>.Setfocus;

If I try this, Delphi says that

EndFileViewer.SetFocus is an invalid identifier

What am I doing wrong here ???

In your case - EndFileViewer.SetFocus;

>Vik, I'm not sure that's a good idea though. If the user wants > to scroll the text, he might be unable to do it.

I will try it out if scrolling is unable i  this case.
Text scolling is the only thing I want to allow for the user.

> mathes, no comments for me at all? :-)

Sure, I will try your idea, too.

With kind regards

Christian


0
 
LVL 3

Expert Comment

by:Matvey
ID: 1359459
>Sure, I will try your idea, too.

-You saw my first comment, right?

What is "EndFileViewer"? I think you mixed a caption of something with it's name. Click on the control on the form and see the "Name" property. I can't tell you mach. Also might be because it's a control of another form, not the one your code is in. In this case you have to write something like:
<form_name>.<control_name>.SetFocus;
0
 
LVL 10

Accepted Solution

by:
viktornet earned 50 total points
ID: 1359460
Hello guys. I think Matvey's idea is great, and you can derive a component from TMemo and disable it from allowing people work with it. To make this use exactly what Matvey says...but if you want to use my method then just use it, I tried it and it works, and it allows you scrolling,, and at the same time the user cannot change anything, or highlight anything within the memo..
You need to do thi...
Put this in OnEnter of the memo...

NameOfButton.SetFocus;//now the user is able to scroll down the memo...

Regards,
Viktor Ivanov


0
 

Author Comment

by:mathes
ID: 1359461
Dear Matvey,

I tried to implement your idea with your own memo field, in order to lock the mouse,
however I have some problems to implement this. How can I create a connection between your

  TNoSelMemo = class(TMemo)  type

and my own original Delphi memo component which I added to my form?

Of course I could copy your code into my module, but how does Delphi know that
I want to control my TMemo object with this code lines? Will your code and
my TMemo element really cooperate? I guess they don't know from each other.

With kind regards

Christian






0
 
LVL 3

Expert Comment

by:Matvey
ID: 1359462
You can either register the new memo component into your component palete, put it on your form and use it instead of your memo. Put the code above into a new unit and add a register procedure.

Interface
.....
  procedure Register;
Implementetion
.....
procedure Register;
begin
  RegisterComponents('Samples', [TNoSelMemo]);
end;

-Then install this component using Component/Install Component...

Or you can create it manually at run-time:

  TForm1 = class(TForm)
    procedure FormCreate(Sender: TObject);
    procedure FormDestroy(Sender: TObject);
  private
    memo1: TNoSelMemo;
  end;

procedure TForm1.FormCreate(Sender: TObject);
begin
........
  memo1 := TNoSelMemo.Create(Self);
  memo1.parent := self
  memo1.Setbounds(20, 30, 100, 200);
........
end;

-and don't forget:

procedure TForm1.FormDestroy(Sender: TObject);
begin
  memo1.free;
end;

--Matvey
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!

 
LVL 10

Expert Comment

by:viktornet
ID: 1359463
( Hey Mathes reject my naswer and let Matvey answer the ? so he can recieve the points :)

Regards,
Viktor Ivanov
0
 
LVL 3

Expert Comment

by:Matvey
ID: 1359464
Hi Vik, I'm not sure my idea is much better than yours, after all it's more code and harder to exaplin to a beginner, but also it looks a bit more specific...

PS I don't really need the points. You can use my idea and accept Vik's answere - I'll be hapy...
0
 

Author Comment

by:mathes
ID: 1359465
Hi experts,

I still have trouble with the paralyzing of the mouse.
I currently prefer the method with SetFocus, because it is rather easy to
implement it for a Delphi novice like me. (Before I can assess the other idea
- the alternative TMemo control - I will have to consult some books first,
so please have patience with me...)
At least the SetFocus idea should be easy to implement. I still have trouble
with this strange "invalid identifier" message. I meanwhile created a test
application especially bound for testing the SetFocus idea.
It consists only of one form and one command button, nothing else.
I am sure that I don't mix caption and name. As my application consists only of
one form, I don't need to add the name of the form. It should be sufficient to
write:

Button1.SetFocus.

But if I do this, I always get this error message. I changed the name of the
command button control several times, but Delphi in all cases complains about
an invalid identifier. Now I wonder whether this is perhaps a known bug in
Delphi 3.0
I have heard about File patches for 3.01 and 3.02. Do you think that updating
my Delphi from 3.0 to 3.02 will cure my problem with SetFocus ?

With kind regards

Christian


0
 
LVL 10

Expert Comment

by:viktornet
ID: 1359466
Are you sure you haven't changed the name of the button, or as you said try writing it like this Form1.Button1.SetFocus;

//Vik
0
 

Author Comment

by:mathes
ID: 1359467

Dear Viktor,

thanks for your comment.
I tried it with form, although not required, because only 1 form in the test program. I changed the name of the command button to try several identifiers, of course I adjusted the name in the setfocus statement, too.

With kind regards

Christian
0
 
LVL 10

Expert Comment

by:viktornet
ID: 1359468
And??? Did it work?

//Vik
0
 
LVL 10

Expert Comment

by:viktornet
ID: 1359469
Tell me your E-mail address...I'll send you a working demo with the code....

Regards,
Viktor Ivanov
0
 

Author Comment

by:mathes
ID: 1359470
Dear Vik,

thank you for this great offer !!
My e-mail adress is: circe@muc.de

SetFocus still does not work on my PC.
As soon as I recieve your mail, I will send you my simple
test program which shows that SetFocus does not work.

With kind regards

Christian

0
 
LVL 10

Expert Comment

by:viktornet
ID: 1359471
Are you sure you haven't changed the name of the button, or as you said try writing it like this Form1.Button1.SetFocus;

//Vik
0
 

Author Comment

by:mathes
ID: 1359472
hi experts.

due to technical problems with my monitor - the picture is almost invisible - i must return for a few weeks and return later. As soon as my problems are fixed I will rate your answer. Sorry for the inconvience.
0

Featured Post

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!

Join & Write a Comment

This article explains how to create forms/units independent of other forms/units object names in a delphi project. Have you ever created a form for user input in a Delphi project and then had the need to have that same form in a other Delphi proj…
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…
Illustrator's Shape Builder tool will let you combine shapes visually and interactively. This video shows the Mac version, but the tool works the same way in Windows. To follow along with this video, you can draw your own shapes or download the file…
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

746 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

12 Experts available now in Live!

Get 1:1 Help Now