Jump to content
Bart Kindt

Setting a TSplitter position at runtime

Recommended Posts

I have a simple test Form with two TMemo's.

The top TMemo align is set as alClient.

The second is set as alBottom.

In between I put a TSplitter.

 

I want to set the vertical position of the splitter at runtime. Basically, I want to save the form, and later load it so the two Memo's are set as the User may have set them before.

No matter what I try, I cannot make the Splitter or either of the Memo's to change size (vertically). They do not respond to any runtime setting of 'Top', Height, etc.

Really, if I set the bottom TMemo.Top at a position, the top TMemo should automatically change size to accomodate. Does not work.

I must be missing something totally obvious.

 

unit Unit2;

interface

uses
  Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants, System.Classes, Vcl.Graphics,
  Vcl.Controls, Vcl.Forms, Vcl.Dialogs, Vcl.ExtCtrls, Vcl.StdCtrls;

type
  TForm2 = class(TForm)
    Memo1: TMemo;
    Memo2: TMemo;
    GroupBox1: TGroupBox;
    Button1: TButton;
    Splitter1: TSplitter;
    procedure Button1Click(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  Form2: TForm2;

implementation

{$R *.dfm}

procedure TForm2.Button1Click(Sender: TObject);
begin
  Splitter1.top := 100; // Does not work
  Memo2.top := 100;     // Does not work
  Memo1.Height := 100;  // Does not work
end;

end.

 

Share this post


Link to post

You must set the height of the memo with alBottom. Everything else will adjust automatically (unless the splitter  acts up then it will be moved above the memo with alClient 😞 in that case you can hopefully set the splitter's top position to move it back between the memos where it belongs).

  • Like 1

Share this post


Link to post

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×