Board index » delphi » Align property not working

Align property not working

I am trying to create a program, which is essentially notepad with multiple
pages, in an effort to familiarise myself with various somponents and
options. The code below is what I have so far, and it has an interesting
problem. When I create a new tabsheet, and then a new memo component on that
sheet, setting the Align property of the TMemo does not seem to work, and I
cant work out why. The tabsheet's are being created along with the Memo's,
but I have feeling that I am not doing some thing right, and that is causing
the problem. If anyone could spot the problem, or come up with a work
around, it would be much appreciated. Also any suggestions will be taken
with open arms.

--------code starts here--------
unit Main;

interface

uses
  Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
  Menus, StdCtrls, ComCtrls;

type
  TMainForm = class(TForm)
    PageControl: TPageControl;
    MainMenu1: TMainMenu;
    mnuFile: TMenuItem;
    mnuFileNew: TMenuItem;
    N1: TMenuItem;
    mnuFileExit: TMenuItem;
    UnTitledSheet: TTabSheet;
    UnTitledMemo: TMemo;
    procedure mnuFileNewClick(Sender: TObject);
    procedure mnuFileExitClick(Sender: TObject);
    procedure FormCreate(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  MainForm: TMainForm;
  NewSheet : TTabSheet;
  NewMemo : TMemo;
  UntitledCount : Integer;

implementation

{$R *.DFM}

procedure TMainForm.mnuFileNewClick(Sender: TObject);
begin
  NewSheet := TTabSheet.Create(PageControl);
  NewSheet.PageControl := PageControl;
  Inc(UntitledCount); {increment the untitled count by 1}
  NewSheet.Caption := 'Untitled' + IntToStr(UntitledCount);

  NewMemo := TMemo.Create(NewSheet);
  NewMemo.Align := alClient;
  NewMemo.ParentWindow := Newsheet.Handle;
  with NewSheet do
    {size the memo, as alClient does not seem to work}

NewMemo.SetBounds(ClientRect.Left,ClientRect.Top,ClientRect.right,ClientRect
.bottom);
    NewMemo.Visible := true;
end;

procedure TMainForm.mnuFileExitClick(Sender: TObject);
begin
  Close;
end;

procedure TMainForm.FormCreate(Sender: TObject);
begin
  UnTitledCount := 1;{because there is a blank sheet and memo at start up}
end;

end.

 

Re:Align property not working


"Craig Reynolds" <reynoldscra...@hotmail.com> a crit dans le message
news:3aa5d661$0$8181@echo-01.iinet.net.au...

Quote
> I am trying to create a program, which is essentially notepad with
multiple
> pages, in an effort to familiarise myself with various somponents and
> options. The code below is what I have so far, and it has an interesting
> problem. When I create a new tabsheet, and then a new memo component on
that
> sheet, setting the Align property of the TMemo does not seem to work, and

Try  :

  NewSheet := TTabSheet.Create(PageControl);
  NewSheet.PageControl := PageControl;
//  Inc(UntitledCount);  not needed
  NewSheet.Caption := 'Untitled' + intToStr(PageControl.PageCount);
// so no need to do your UnTitledCount := 1;
  NewMemo := TMemo.Create(NewSheet);
  NewMemo.Align := alClient;
  NewMemo.Parent := Newsheet;

patrick

Re:Align property not working


In article <3aa5d661$0$8...@echo-01.iinet.net.au>, "Craig Reynolds"

Quote
<reynoldscra...@hotmail.com> writes:
>  NewMemo := TMemo.Create(NewSheet);
>  NewMemo.Align := alClient;
>  NewMemo.ParentWindow := Newsheet.Handle;

  NewMemo := TMemo.Create(NewSheet);
  NewMemo.Parent := Newsheet;
  NewMemo.Align := alClient;

ParentWindow is for use with non-VCL components (and maybe using it by-passes
some of the setting code in TComponent).

Setting the Parent before changing any properties is good practice and might
also have some deleterious effect.

Alan Lloyd
alangll...@aol.com

Re:Align property not working


Its works now, thanks for the input guys!!

Quote
"Craig Reynolds" <reynoldscra...@hotmail.com> wrote in message

news:3aa5d661$0$8181@echo-01.iinet.net.au...
Quote
> I am trying to create a program, which is essentially notepad with
multiple
> pages, in an effort to familiarise myself with various somponents and
> options. The code below is what I have so far, and it has an interesting
> problem. When I create a new tabsheet, and then a new memo component on
that
> sheet, setting the Align property of the TMemo does not seem to work, and
I
> cant work out why. The tabsheet's are being created along with the Memo's,
> but I have feeling that I am not doing some thing right, and that is
causing
> the problem. If anyone could spot the problem, or come up with a work
> around, it would be much appreciated. Also any suggestions will be taken
> with open arms.

> --------code starts here--------
> unit Main;

> interface

> uses
>   Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms,
Dialogs,
>   Menus, StdCtrls, ComCtrls;

> type
>   TMainForm = class(TForm)
>     PageControl: TPageControl;
>     MainMenu1: TMainMenu;
>     mnuFile: TMenuItem;
>     mnuFileNew: TMenuItem;
>     N1: TMenuItem;
>     mnuFileExit: TMenuItem;
>     UnTitledSheet: TTabSheet;
>     UnTitledMemo: TMemo;
>     procedure mnuFileNewClick(Sender: TObject);
>     procedure mnuFileExitClick(Sender: TObject);
>     procedure FormCreate(Sender: TObject);
>   private
>     { Private declarations }
>   public
>     { Public declarations }
>   end;

> var
>   MainForm: TMainForm;
>   NewSheet : TTabSheet;
>   NewMemo : TMemo;
>   UntitledCount : Integer;

> implementation

> {$R *.DFM}

> procedure TMainForm.mnuFileNewClick(Sender: TObject);
> begin
>   NewSheet := TTabSheet.Create(PageControl);
>   NewSheet.PageControl := PageControl;
>   Inc(UntitledCount); {increment the untitled count by 1}
>   NewSheet.Caption := 'Untitled' + IntToStr(UntitledCount);

>   NewMemo := TMemo.Create(NewSheet);
>   NewMemo.Align := alClient;
>   NewMemo.ParentWindow := Newsheet.Handle;
>   with NewSheet do
>     {size the memo, as alClient does not seem to work}

NewMemo.SetBounds(ClientRect.Left,ClientRect.Top,ClientRect.right,ClientRect

- Show quoted text -

Quote
> .bottom);
>     NewMemo.Visible := true;
> end;

> procedure TMainForm.mnuFileExitClick(Sender: TObject);
> begin
>   Close;
> end;

> procedure TMainForm.FormCreate(Sender: TObject);
> begin
>   UnTitledCount := 1;{because there is a blank sheet and memo at start up}
> end;

> end.

Other Threads