Recent

Author Topic: Setting tab indent width in TMemo or TStringList  (Read 2402 times)

Fantablup

  • Full Member
  • ***
  • Posts: 170
Setting tab indent width in TMemo or TStringList
« on: May 10, 2021, 06:07:04 pm »
I have a big problem setting the tab width when inserting the #9 character in any string.
The default tab width is too long.
I googled about Lazarus, and how to set default tab width, but nothing.
Tmemo and TStringList dont have any tab width settings.

It seems that this could be a big problem for others too.

I just neet to set the tab width to 6, but i just can't figure out how.
i'm adding strings to TStringList, and after adding it to a TMemo.
Is it possible to set tab width to strings in TStringList? and also use tab width on TMemo when user press the tab?

I tried finding a soulution, but after six hours searching i gave up the search.

lucamar

  • Hero Member
  • *****
  • Posts: 4219
Re: Setting tab indent width in TMemo or TStringList
« Reply #1 on: May 10, 2021, 08:05:09 pm »
The only way to do something like that would be replacing the tab character by the corresponding number of spaces.

For TStringList you could it overriding all string-addition methods: Add, Insert, etc.

For TMemo the problem you would have to do the same for the inner Lines property (not easy)

Of course, doing that would destroy the Tab character itself, so if you want to keep it you'll have to find other method dealing only with how (or what) is "drawn" when a Tab character is encountered.

It's not a trivial problem and I'd strongly suggest that you find/use another control already prepared for that, like e.g. TSynEdit.
Turbo Pascal 3 CP/M - Amstrad PCW 8256 (512 KB !!!) :P
Lazarus/FPC 2.0.8/3.0.4 & 2.0.12/3.2.0 - 32/64 bits on:
(K|L|X)Ubuntu 12..18, Windows XP, 7, 10 and various DOSes.

Fantablup

  • Full Member
  • ***
  • Posts: 170
Re: Setting tab indent width in TMemo or TStringList
« Reply #2 on: May 10, 2021, 11:17:09 pm »
Thanks lucamar!

I thought this would be a big problem.
Using spaces instead just destroys the tab character, so that is not a solution as you also say.
Well, nothing can be done with these controls then.

Thanks for the tip on Tsynedit.
I tried it.
I can use that i think.
« Last Edit: May 10, 2021, 11:29:48 pm by Fantablup »

Fantablup

  • Full Member
  • ***
  • Posts: 170
Re: Setting tab indent width in TMemo or TStringList
« Reply #3 on: May 10, 2021, 11:36:53 pm »
Using TsynEdit works.

Thanks again for this good tip  :)

Fantablup

  • Full Member
  • ***
  • Posts: 170
Re: Setting tab indent width in TMemo or TStringList
« Reply #4 on: May 10, 2021, 11:58:51 pm »
That means that working with TMemo/TDBMemo or a Tstringlist is just no go when you need to set tab width?
It seems to me that these components is not ready to use then.

lucamar

  • Hero Member
  • *****
  • Posts: 4219
Re: Setting tab indent width in TMemo or TStringList
« Reply #5 on: May 11, 2021, 12:17:08 am »
It seems to me that these components is not ready to use then.

They are, and quite useful; only they are very simple, no-frills, text-editing controls, not what one would term "text-processing" ones.
Turbo Pascal 3 CP/M - Amstrad PCW 8256 (512 KB !!!) :P
Lazarus/FPC 2.0.8/3.0.4 & 2.0.12/3.2.0 - 32/64 bits on:
(K|L|X)Ubuntu 12..18, Windows XP, 7, 10 and various DOSes.

Fantablup

  • Full Member
  • ***
  • Posts: 170
Re: Setting tab indent width in TMemo or TStringList
« Reply #6 on: May 11, 2021, 12:28:52 am »
I agree that they are simple.
But, this simple thing should be in them. It may not be simple to implement it though.
Anyway, TRichMemo should have this.
I saw the TMemo in Delphi has some strange implementation on it. Not in the object inspector, but through the perform function.

jamie

  • Hero Member
  • *****
  • Posts: 6090
Re: Setting tab indent width in TMemo or TStringList
« Reply #7 on: May 13, 2021, 01:03:26 am »
the windows Memo can do the Sendmessage(handle, EM_SETTABSTOPS, ?, ?);

where you can have an array of tabs fixed at indexes or used default or custom spacing.
The only true wisdom is knowing you know nothing

 

TinyPortal © 2005-2018