peter2001
asked on
memo text monitoring
hi
say i have a memo on my form
and if the text 'hello' gets typed in how would i make a message box appear
ie
if memo.text = 'hello' then message box 'hello was typed'
thanks pete
say i have a memo on my form
and if the text 'hello' gets typed in how would i make a message box appear
ie
if memo.text = 'hello' then message box 'hello was typed'
thanks pete
If you want to modify what the user is typing into the edit, then try the on key press event
procedure TForm1.Memo1KeyPress(Sende r: TObject; var Key: Char);
begin
If key in ['A'..'Z'] then
begin
beep;
Key:= #0;
end;
end;
would stop all capital letters, you could also make it avoid invalid symbols such as %^&
procedure TForm1.Memo1KeyPress(Sende
begin
If key in ['A'..'Z'] then
begin
beep;
Key:= #0;
end;
end;
would stop all capital letters, you could also make it avoid invalid symbols such as %^&
ASKER
hi
the problem is the text in the memo does not get deleted so how would i go about
showing a message only once as like you say the message pops up every time you press a key in the memo after the word hello is typed
thanks pete
the problem is the text in the memo does not get deleted so how would i go about
showing a message only once as like you say the message pops up every time you press a key in the memo after the word hello is typed
thanks pete
The best option i can think of would be to have a word count function, then to save the count of the number of times a word appears in the memo and then show the message if that changes
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
>how would i go about
>showing a message only once
the hazardous way:
procedure TForm1.Memo1Change(sender : TObject); //just from head, header could sound like this
begin
if pos('hello',memo1.text) > 0 then
begin
showmessage('hello is appeared');
Memo1.onChange := NIL; //unHook this event -> don't forget if you will start new to reassign it
end;
end;
the way i would use:
var
message_showed : Boolean := False; //a local unit-global var,
//could be also in the TForm Class definiton, in case of using mutliple instances in one app
procedure TForm1.Memo1Change(sender : TObject); //just from head, header could sound like this
begin
if not message_showed then
if pos('hello',memo1.text) > 0 then
begin
showmessage('hello is appeared');
message_showed := true; //-> don't forget if you will start new to reset it to false
end;
end;
meikl ;-)
>showing a message only once
the hazardous way:
procedure TForm1.Memo1Change(sender : TObject); //just from head, header could sound like this
begin
if pos('hello',memo1.text) > 0 then
begin
showmessage('hello is appeared');
Memo1.onChange := NIL; //unHook this event -> don't forget if you will start new to reassign it
end;
end;
the way i would use:
var
message_showed : Boolean := False; //a local unit-global var,
//could be also in the TForm Class definiton, in case of using mutliple instances in one app
procedure TForm1.Memo1Change(sender : TObject); //just from head, header could sound like this
begin
if not message_showed then
if pos('hello',memo1.text) > 0 then
begin
showmessage('hello is appeared');
message_showed := true; //-> don't forget if you will start new to reset it to false
end;
end;
meikl ;-)
Thanks for the points, glad I could help
ASKER
thanks for that
thats was just what i wanted
thankyou
pete
thats was just what i wanted
thankyou
pete
ASKER
hi sorry to bother you could you help me on 1 more thing with this
i have been tring to read from a flatedit box
procedure TForm1.Memo1Change(Sender: TObject);
begin
If WordCountformemo1<>WordCou nt(flatedi t1.text,me mo1.Text) then
begin
WordCountformemo1:= WordCount(flatedit1.text,m emo1.Text) ;
ShowMessage('A new hello has been found');
end;
end;
it runs ok but does not make a popup message nothing
any ideas why?
i have been tring to read from a flatedit box
procedure TForm1.Memo1Change(Sender:
begin
If WordCountformemo1<>WordCou
begin
WordCountformemo1:= WordCount(flatedit1.text,m
ShowMessage('A new hello has been found');
end;
end;
it runs ok but does not make a popup message nothing
any ideas why?
I dont seem to have a TFlatEdit in Delphi 7, however I did test the code with a normal edit and it worked correctly, the only thing I did notice is that the code is case sensitive, could this be causeing your problem? the following version is not case sensitive
Function WordCount(Word,text: string): integer;
begin
result:= 0;
while pos(uppercase(Word),upperc ase(text)) <>0 do
begin
Result := Result+1;
Delete(text,1,pos(Word,tex t)+length( Word)-1);
end;
end;
David
Function WordCount(Word,text: string): integer;
begin
result:= 0;
while pos(uppercase(Word),upperc
begin
Result := Result+1;
Delete(text,1,pos(Word,tex
end;
end;
David
ASKER
hi
yeah the flatedit did not work but the normal edit worked ok
i will start another question so i can give you more points to help me sort this out
here is link to it
https://www.experts-exchange.com/questions/21481810/memo-word-monitoring.html
as i want to check for about 7 different words i thought i would be able to do it like this
Function WordCount(Word,text: string): integer;
begin
result:= 0;
while pos(uppercase(Word),upperc ase(text)) <>0 do
begin
Result := Result+1;
Delete(text,1,pos(Word,tex t)+length( Word)-1);
end;
end;
Function WordCount1(Word,text: string): integer;
begin
result:= 0;
while pos(uppercase(Word),upperc ase(text)) <>0 do
begin
Result := Result+1;
Delete(text,1,pos(Word,tex t)+length( Word)-1);
end;
end;
procedure TKeylogger.Memo1Change(Sen der: TObject);
begin
If WordCountformemo1<>WordCou nt(edit1.t ext,memo1. Text) then
begin
WordCountformemo1:= WordCount(edit1.text,memo1 .Text);
ShowMessage('A new '+edit1.text+' has been found');
end;
begin
If WordCountformemo1<>WordCou nt1(edit2. text,memo1 .Text) then
begin
WordCountformemo1:= WordCount1(edit2.text,memo 1.Text);
ShowMessage('A new '+edit2.text+' has been found');
end;
end;
end;
but this then soon as 1 word is found it just repeats the popup messasge's . its fine if i just check the 1 word
would it be better to have the words in list seperated by commas as am not sure how to do it
yeah the flatedit did not work but the normal edit worked ok
i will start another question so i can give you more points to help me sort this out
here is link to it
https://www.experts-exchange.com/questions/21481810/memo-word-monitoring.html
as i want to check for about 7 different words i thought i would be able to do it like this
Function WordCount(Word,text: string): integer;
begin
result:= 0;
while pos(uppercase(Word),upperc
begin
Result := Result+1;
Delete(text,1,pos(Word,tex
end;
end;
Function WordCount1(Word,text: string): integer;
begin
result:= 0;
while pos(uppercase(Word),upperc
begin
Result := Result+1;
Delete(text,1,pos(Word,tex
end;
end;
procedure TKeylogger.Memo1Change(Sen
begin
If WordCountformemo1<>WordCou
begin
WordCountformemo1:= WordCount(edit1.text,memo1
ShowMessage('A new '+edit1.text+' has been found');
end;
begin
If WordCountformemo1<>WordCou
begin
WordCountformemo1:= WordCount1(edit2.text,memo
ShowMessage('A new '+edit2.text+' has been found');
end;
end;
end;
but this then soon as 1 word is found it just repeats the popup messasge's . its fine if i just check the 1 word
would it be better to have the words in list seperated by commas as am not sure how to do it
using the onchange-event
.....
if pos('hello',memo1.text) > 0 then
showmessage('hello is appeared');
.....
of course is once hello typed and never deleted,
this message comes with every keystroke into the memo
meikl ;-)