Recent

Author Topic: Rows to the component memo  (Read 7203 times)

elidorio

  • Sr. Member
  • ****
  • Posts: 295
Rows to the component memo
« on: September 29, 2014, 04:21:31 pm »
Hello all,

How to add rows to the component memo ?

[] 's

Edson
Lazarus 1.4.4 | FPC 2.6.4 | Windows / Linux Debian

Mike.Cornflake

  • Hero Member
  • *****
  • Posts: 1260
Re: Rows to the component memo
« Reply #1 on: September 29, 2014, 04:54:54 pm »
Is this what you're after?

Code: [Select]
Memo1.Lines.Add('');
Lazarus Trunk/FPC Trunk on Windows [7, 10]
  Have you tried searching this forum or the wiki?:   http://wiki.lazarus.freepascal.org/Alternative_Main_Page
  BOOKS! (Free and otherwise): http://wiki.lazarus.freepascal.org/Pascal_and_Lazarus_Books_and_Magazines

wp

  • Hero Member
  • *****
  • Posts: 11923
Re: Rows to the component memo
« Reply #2 on: September 29, 2014, 05:25:47 pm »
Quote
[] 's
?

elidorio

  • Sr. Member
  • ****
  • Posts: 295
Re: Rows to the component memo
« Reply #3 on: September 29, 2014, 07:26:02 pm »
I want to insert a new row with the ENTER key.
Lazarus 1.4.4 | FPC 2.6.4 | Windows / Linux Debian

howardpc

  • Hero Member
  • *****
  • Posts: 4144
Re: Rows to the component memo
« Reply #4 on: September 29, 2014, 08:02:44 pm »
The default behaviour of TMemo when you press [Enter] is to move you to the start of a new line (row) below any existing ones.
How do you want this behaviour modified?

wp

  • Hero Member
  • *****
  • Posts: 11923
Re: Rows to the component memo
« Reply #5 on: September 29, 2014, 08:36:08 pm »
No, when WantReturns is true (and this is the default), the ENTER key adds a new line at the position of the cursor (just tested on Windows).

elidorio

  • Sr. Member
  • ****
  • Posts: 295
Re: Rows to the component memo
« Reply #6 on: September 29, 2014, 09:12:13 pm »
The problem is, use the command below in the onKeyPress Event to Enter work in the form, only now the DBmemo component does not work due to this command.

if key = # 13 then
begin
Key: = # 0;
Perform (Wm_NextDlgCtl .0 .0);
SelectNext (activecontrol, True, True);
end;

How to bypass this?
Lazarus 1.4.4 | FPC 2.6.4 | Windows / Linux Debian

Mike.Cornflake

  • Hero Member
  • *****
  • Posts: 1260
Re: Rows to the component memo
« Reply #7 on: September 29, 2014, 09:23:30 pm »
What is that code doing?   Near as I can make out, when the user hits return in a DBMemo, that code cancels the Return key and sets focus to the next control (actually, if it's doing what I *think* it's doing it sets focus to the next control, and then sets focus to the control after that).   Is this what you mean by "does not work"? 

Forget  all that focus the next control stuff...

Try something like...
Code: [Select]
if key = # 13 then
begin
  TDBMemo(Sender).Lines.Add('');
  key := #0;
end;
Lazarus Trunk/FPC Trunk on Windows [7, 10]
  Have you tried searching this forum or the wiki?:   http://wiki.lazarus.freepascal.org/Alternative_Main_Page
  BOOKS! (Free and otherwise): http://wiki.lazarus.freepascal.org/Pascal_and_Lazarus_Books_and_Magazines

elidorio

  • Sr. Member
  • ****
  • Posts: 295
Re: Rows to the component memo
« Reply #8 on: September 29, 2014, 10:05:58 pm »
I tried to use this code and this generating AV errors.
Lazarus 1.4.4 | FPC 2.6.4 | Windows / Linux Debian

Mike.Cornflake

  • Hero Member
  • *****
  • Posts: 1260
Re: Rows to the component memo
« Reply #9 on: September 29, 2014, 10:53:11 pm »
Did you set a breakpoint to find out why?
Is Sender being passed, or is it nil? 
Is Sender even a TDBMemo?
Are you sure they were AV errors?  That's a data aware control.  Is the dataset in edit mode?
Without you posting full code, we're working in the dark, which is frankly frustrating :-(

Assumptions in my code:
  You put the code in the TDBMemo.OnKeyPressed (and not a normal TMemo.OnKeyPressed)
  You're not manually calling the OnKeyPressed function and passing nil

Please read this:
http://wiki.lazarus.freepascal.org/Lazarus_Faq#What_is_the_correct_way_to_ask_questions_in_the_forum.3F
« Last Edit: September 29, 2014, 10:58:22 pm by Mike.Cornflake »
Lazarus Trunk/FPC Trunk on Windows [7, 10]
  Have you tried searching this forum or the wiki?:   http://wiki.lazarus.freepascal.org/Alternative_Main_Page
  BOOKS! (Free and otherwise): http://wiki.lazarus.freepascal.org/Pascal_and_Lazarus_Books_and_Magazines

lazjump

  • Jr. Member
  • **
  • Posts: 61
Re: Rows to the component memo
« Reply #10 on: September 30, 2014, 01:47:53 am »
Hi Elidorio,

I think I know what you're trying to do.

You want to make your form to use Enter key to go to the next control, like the Tab key. So you type some code in the form's OnKeyPress event to make the Enter key to go to the next control. But when the current control is a memo, you want the Enter key to function normally (to add lines to the memo).

If that is what you're trying to do, then the solution is simple. Add this on the first line of the OnKeyPress event handler:

Code: [Select]
if Self.ActiveControl is TMemo then Exit;
I thought Delphi was expensive until I learned the price of ExtJS

Mike.Cornflake

  • Hero Member
  • *****
  • Posts: 1260
Re: Rows to the component memo
« Reply #11 on: September 30, 2014, 02:09:58 am »
Hi Elidorio,

I think I know what you're trying to do.

You want to make your form to use Enter key to go to the next control, like the Tab key. So you type some code in the form's OnKeyPress event to make the Enter key to go to the next control. But when the current control is a memo, you want the Enter key to function normally (to add lines to the memo).

If that is what you're trying to do, then the solution is simple. Add this on the first line of the OnKeyPress event handler:

Code: [Select]
if Self.ActiveControl is TMemo then Exit;

Absolutely amazing bit of detective work there.  Yes, this would make sense of the issues...  Nice work :-)   I *think* he's using TDBMemo's, but either way, the following change might be worth doing...

Code: [Select]
if Self.ActiveControl is TCustomMemo then Exit;
« Last Edit: September 30, 2014, 02:11:54 am by Mike.Cornflake »
Lazarus Trunk/FPC Trunk on Windows [7, 10]
  Have you tried searching this forum or the wiki?:   http://wiki.lazarus.freepascal.org/Alternative_Main_Page
  BOOKS! (Free and otherwise): http://wiki.lazarus.freepascal.org/Pascal_and_Lazarus_Books_and_Magazines

elidorio

  • Sr. Member
  • ****
  • Posts: 295
Re: Rows to the component memo [Solved]
« Reply #12 on: September 30, 2014, 12:30:39 pm »
Hello All,
Fantastic, worked perfectly.
Thank you all so much.
Follow the code

--
Edson
Lazarus 1.4.4 | FPC 2.6.4 | Windows / Linux Debian

lazjump

  • Jr. Member
  • **
  • Posts: 61
Re: Rows to the component memo
« Reply #13 on: September 30, 2014, 02:36:00 pm »
Glad it works.

And thanks to Mike.Cornflake, the code works with TMemo and TDBMemo.
I thought Delphi was expensive until I learned the price of ExtJS

 

TinyPortal © 2005-2018