Board index » delphi » autoindent in TMemo

autoindent in TMemo

Does anybody know how to program this? I tried it myself using an event
handler for onKeyPress, but the problem is that the jump to the next line
happens AFTER the onKeyPress handler, so my method gives me 2 new lines for
each enter-key I press, instead of one (well, that's a nice effect, too, I
admit, but not quite what I wanted...)

Perhaps it has something to do with overriding the event handler, but I
don't know how to do this. I guess it would be something like:

if Key = 13 then   // ENTER-key pressed
    // do auto-indent stuff, place spaces if necessary etc...
else
    // do default stuff, just add the character to the memo component

Is there somebody out there who has done this before? Please let me know.

Please cc to me privatly at y...@fibolite.hogent.be

TIA,

Yves

 

Re:autoindent in TMemo


Does anybody know how to program this? I tried it myself using an event
handler for onKeyPress, but the problem is that the jump to the next line
happens AFTER the onKeyPress handler, so my method gives me 2 new lines for
each enter-key I press, instead of one (well, that's a nice effect, too, I
admit, but not quite what I wanted...)

Perhaps it has something to do with overriding the event handler, but I
don't know how to do this. I guess it would be something like:

if Key = 13 then   // ENTER-key pressed
    // do auto-indent stuff, place spaces if necessary etc...
else
    // do default stuff, just add the character to the memo component

Is there somebody out there who has done this before? Please let me know.

Please cc to me privatly at y...@fibolite.hogent.be

TIA,

Yves

Re:autoindent in TMemo


Quote

>if Key = 13 then   // ENTER-key pressed
>    // do auto-indent stuff, place spaces if necessary etc...
>else
>    // do default stuff, just add the character to the memo component

>Is there somebody out there who has done this before? Please let me know.

try this ...

procedure TForm1.Memo1KeyPress(Sender: TObject; var Key: Char);
begin
  if Key = #13 then begin  // Check for [ENTER]-Key
    Memo1.SelText := #13#10 + '   test';  // "manually" [ENTER] + indent
stuff
    Key := #0;  // Kill "old" [ENTER], that was pressed
  end;
end;

Bye
  Sven

Other Threads