Recent

Author Topic: [Solved for Win] TMemo tab width  (Read 7635 times)

milleratotago

  • New Member
  • *
  • Posts: 12
[Solved for Win] TMemo tab width
« on: June 28, 2014, 12:46:11 am »
Is it possible to change the width (number of characters) of a tabbed field shown in a TMemo?
Thanks,
« Last Edit: June 28, 2014, 10:30:35 pm by milleratotago »

howardpc

  • Hero Member
  • *****
  • Posts: 4144
Re: TMemo tab width
« Reply #1 on: June 28, 2014, 08:02:43 am »
TMemo is a control designed to display lines of strings (TStrings).
What exactly do you mean by a "tabbed field" shown in a TMemo?

milleratotago

  • New Member
  • *
  • Posts: 12
Re: TMemo tab width
« Reply #2 on: June 28, 2014, 11:07:36 am »
I want to be able to control the widths of strings like this:
Field1<tab>Field2<tab>Field3<tab>Field4
F1<tab>F2<tab>F3<tab>F4
So, for example, I might want each field to occupy 8 spaces, or 12, or 15.
Basically, I want to adjust the field widths according to the longest string in each, so that the fields will line up vertically.  The default width appears to be 8 characters, but sometimes I need more, so the columns do not line up.



Mike.Cornflake

  • Hero Member
  • *****
  • Posts: 1269
Re: TMemo tab width
« Reply #3 on: June 28, 2014, 11:19:35 am »
I've had a look in stdctrls.pp.  I can't see that this functionality has been surfaced in the LCL :-(  Though more experienced users will hopefully correct me.

If you're using Windows, you could try following code similar to here...
http://www.experts-exchange.com/Programming/Languages/Pascal/Delphi/Q_22493724.html

Absolutely no idea if this will work in Lazarus.  Also, this stops your app being cross platform (unless you find and implement similar workarounds for each of the other widgetsets)
Lazarus Trunk/FPC latest fixes on Windows 11
  I'm getting old and stale.  Slowly getting used to git, I'll get there...

howardpc

  • Hero Member
  • *****
  • Posts: 4144
Re: TMemo tab width
« Reply #4 on: June 28, 2014, 04:51:19 pm »
I don't know if this is possible with TMemo.
However, it is possible with TListBox. You need to set the Style to lbOwnerDrawxxx and write your own OnDrawItem handler (or make a TCustomListBox descendant and override its virtual DrawItem(...) procedure).

milleratotago

  • New Member
  • *
  • Posts: 12
Re: TMemo tab width
« Reply #5 on: June 28, 2014, 10:28:55 pm »
Thanks for the suggestions.  In case anyone else is interested, the following 2-step solution works under Windows:

1. Add LCLIntf to the Uses statement.

2. Include the following two lines in FormCreate for the form using your TMemo (say, MyTMemo):

     Const TabInc : LongInt = 60;   //  Increasing this number increases the width of the tabbed field.

     SendMessage(MyTMemo.Handle,$00CB,1,LongInt(@TabInc));  // $00CB is the "EM_SetTabStops" value found in jwawinuser.pas

Note that the value specified for TabInc is NOT the number of characters.  I suspect it is the number of pixels, but that's not critical in my application so I haven't worked that out.


Mike.Cornflake

  • Hero Member
  • *****
  • Posts: 1269
Re: [Solved for Win] TMemo tab width
« Reply #6 on: June 28, 2014, 10:50:51 pm »
Sincere apologies.  The page I was *supposed* to post contained the code you've found.  Looks like I copy/pasted the wrong link.  The page I had found explained that the number is an odd number used by dialogs, and contained a conversion formula from pixels to the value required for the sendmessage...

Glad you solved this on your own, and thanks for sharing the solution :-)
Lazarus Trunk/FPC latest fixes on Windows 11
  I'm getting old and stale.  Slowly getting used to git, I'll get there...

 

TinyPortal © 2005-2018