pascaltform

"OK" Button (TButton) not showing on Tform (Pascal)


I have a form (Tform) which works fine.

I have added another form which shows the TEdit and TLabel objects, but not the TButton object will not show on the form. The code is below.

procedure LoadQtyForm;

begin
    try
    frmChkQty := TForm.Create(nil);
    frmChkQty.Width := 400;
    frmChkQty.Height := 200;
    frmChkQty.Caption := 'Check, Confirm, Change Quantity';
    frmChkQty.Position := poScreenCenter;
    frmChkQty.BorderStyle := bsSingle;
    frmChkQty.Name := 'SecondaryForm';

    { Panel within Form }
    frmChkQtyTopPnl := TPanel.Create(frmChkQty);
    frmChkQtyTopPnl.Parent := frmChkQty;
    frmChkQtyTopPnl.Align := alclient;

    { OK button }
    frmChkQtybtnOK := TButton.Create(frmChkQtyTopPnl);
    //frmChkQtybtnOK := TButton.Create(Self);
    frmChkQtybtnOK.Parent := frmChkQtyTopPnl;
    frmChkQtybtnOK.left := 50; //300
    frmChkQtybtnOK.Top := 50;  //170
    frmChkQtybtnOK.Width := 90;
    frmChkQtybtnOK.Height := 20;
    frmChkQtybtnOK.Caption := '&OK';
    frmChkQtybtnOK.OnClick := 'ChkQtyOKClick';
    //frmChkQtybtnOK.taborder := 98;
    frmChkQtybtnOK.anchors := akright;
    //frmChkQtybtnOK.anchors := akbottom;

    frmChkQtylblfield := TLabel.Create(frmChkQtyTopPnl);
    frmChkQtylblfield.parent := frmChkQtyTopPnl;
    frmChkQtylblfield.left := 100;
    frmChkQtylblfield.top := 40;
    frmChkQtylblfield.font.size := 12;
    frmChkQtylblfield.caption := 'Current Laser Cut Qty is ';

    { To get Qty that was laser cut }
    frmChkQtyedtfield := TEdit.Create(frmChkQtyTopPnl);
    frmChkQtyedtfield.parent := frmChkQtyTopPnl;
    frmChkQtyedtfield.left := 275;
    frmChkQtyedtfield.top := 80;
    frmChkQtyedtfield.Width := 50;
    frmChkQtyedtfield.font.size := 12;
    frmChkQtyedtfield.Text := '1';

    frmChkQtylblfield2 := TLabel.Create(frmChkQtyTopPnl);
    frmChkQtylblfield2.parent := frmChkQtyTopPnl;
    frmChkQtylblfield2.left := 100;
    frmChkQtylblfield2.top := 80;
    frmChkQtylblfield2.font.size := 12;
    frmChkQtylblfield2.caption := 'This Laser Cut Qty is:';

    {
    frmChkQtyedtfield2 := TEdit.Create(frmChkQtyTopPnl);
    frmChkQtyedtfield2.parent := frmChkQtyTopPnl;
    frmChkQtyedtfield2.left := 285;
    frmChkQtyedtfield2.top := 40;
    frmChkQtyedtfield2.Width := 50;
    frmChkQtyedtfield2.Height := 40;
    frmChkQtyedtfield2.font.size := 12;
    frmChkQtyedtfield2.Text := '1';
    }

    frmChkQty.showmodal;
    finally
    frmChkQty.Free
    end;
end;

The following variables have been declared globally:

 //Create Variables for Second form to get/check/confirm quantities
 frmChkQty: Tform;
 frmChkQtyTopPnl:       TPanel;
 frmChkQtybtnOK:        Tbutton;
 frmChkQtylblfield:     TLabel;
 frmChkQtylblfield2:    TLabel;
 frmChkQtyedtfield:     TEdit;
 frmChkQtyedtfield2:    TEdit;

Can anyone tell me why the button is not showing up?

This is part of a script written in a program called Ostendo which uses Pascal.

When the button is clicked it will run this procedure, which is only for testing. I will create further code when I can get the OK button to show on the form.

procedure ChkQtyOKClick;

begin
    frmChkQty.close;
end;

Thanks.


Solution

  • In Delphi button becomes visible when I remove

      frmChkQtybtnOK.anchors := [akright];
    

    So button was really visible, but its coordinates were out of form bounds due to recalculation in process of form showing

    P.S. Move try after TForm.Create