Modify the tabs spacing in a multiedit control (for example TMemo)  

Send By: Q3 Team
Web :
Date: 16/12/99

Tip accessed 725 times


We would sometimes like to be able to configure how many spaces we want that a TAB inserts us
inside a control multiedit.

It is enough with sending him the message EM_SetTabStops to the component.

An example for test it:

  • Make a form, with a TMemo (Memo1) and a TButton (Button1).
  • Put the WantTabs property of Memo1 to TRUE
  • Into OnClick event of Button1 put this code:

     	procedure TForm1.Button1Click(Sender: TObject);
     	const EspaciadoTabs : LongInt = 30;
     	    SendMessage( Memo1.Handle, EM_SetTabStops, 1, Longint( @EspaciadoTabs ) );

    And test the TAB before and after press Button1.

    Tip Update

    Somebody has requested me that it enlarges the trick, so here it goes:

    The message EM_SetTabStops allows to set tab stops in a multiedit control (for example a TMemo).
    The message has these two parameters:

     wParam = (WPARAM) cTabs;               { Numero de paradas de tabulador - number of tab stops }
     lParam = (LPARAM) (LPDWORD) lpdwTabs;  { Array de las paradas que queremos - tab stop array }

    When specifying the number of stops that we want, we have three options:

    An example of how to put several tabulators, for example... two tabulators:

    • Tell him that we want 0 tabulators. That which will make that we disable the tabulator stops in that control

    • Tell him that we only want a tabulator. That will make them to set tabulators to the wide thing from the control to the distance that we specify him (it is the initial code of this trick)

    • Tell him that we want more than 1 tabulator. In that case, it will be able to the tabulators that we have told him, in the distances that we have told him.

     procedure TForm1.Button1Click(Sender: TObject);
       DialogUnitsX  : LongInt;
       PixelsX       : LongInt;
       Tabuladores   : array[0..1] of longint;
       Memo1.WantTabs := true;
       DialogUnitsX := LoWord(GetDialogBaseUnits);
       {Un Tab a 100 pixels}
       Tabuladores[0]:=(100*4) div DialogUnitsX;
       {y otro a 200 pixels}
       Tabuladores[1]:=(200*4) div DialogUnitsX;
       Memo1.Perform( EM_SETTABSTOPS,2,LongInt(@Tabuladores) );

    The mess of the DialogUnits is because in the message EM_SetTabStops the distance is to specify this way it, in Units of Dialogue.
    To have more information of this, consults your file Win32.HLP