how to lock mouse in TMemo ?

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

mathesAsked:
Who is Participating?
 
viktornetConnect With a Mentor Commented:
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
 
viktornetCommented:
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
 
MatveyCommented:
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
Get your problem seen by more experts

Be seen. Boost your question’s priority for more expert views and faster solutions

 
mathesAuthor Commented:

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
 
MatveyCommented:
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
 
mathesAuthor Commented:

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
 
MatveyCommented:
>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
 
mathesAuthor Commented:
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
 
MatveyCommented:
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
 
viktornetCommented:
( Hey Mathes reject my naswer and let Matvey answer the ? so he can recieve the points :)

Regards,
Viktor Ivanov
0
 
MatveyCommented:
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
 
mathesAuthor Commented:
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
 
viktornetCommented:
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
 
mathesAuthor Commented:

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
 
viktornetCommented:
And??? Did it work?

//Vik
0
 
viktornetCommented:
Tell me your E-mail address...I'll send you a working demo with the code....

Regards,
Viktor Ivanov
0
 
mathesAuthor Commented:
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
 
viktornetCommented:
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
 
mathesAuthor Commented:
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
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.