Forum > Beginners

TPanel at runtime

(1/2) > >>

seghele0:
At runtime !
Try to get a "Label" on a TPanel.
The code appears to be correct but the "Label" isn't displayed.
Please help.
 :-[

--- Code: Pascal  [+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i < x.length; i++) { x[i].style.maxHeight='none'; x[i].style.height = Math.min(x[i].clientHeight+15,306)+'px'; x[i].style.resize = "vertical";}};} ---unit Unit1; {$mode objfpc}{$H+} interface uses  Classes, SysUtils, FileUtil, Forms, Controls,  Graphics, Dialogs, StdCtrls, ExtCtrls, Buttons; type   { TFmain }   TFmain = class(TForm)    btnSHOWpanel: TButton;    brnEXIT: TSpeedButton;    procedure brnEXITClick(Sender: TObject);    procedure btnSHOWpanelClick(Sender: TObject);    procedure AnotherButtonClick(Sender: TObject); // eigen proc.    procedure btnTESTClick(Sender: TObject);    // eigen proc.   private   public    Pan1: TPanel;    lblTEXT: TLabel;    btnJAPRINT: TSpeedButton;    btnNEENPRINT: TSpeedButton;  end; var  Fmain: TFmain; implementation {$R *.frm} { TFmain } // Eigen proc. om het Panel te verwijderen.// De naam v.d. proc. moet een extra nieuwe naam hebben.procedure TFmain.AnotherButtonClick(Sender: TObject);begin  FreeAndNil(Pan1);end; // Deze proc. is enkel nodig om een "Showmessage" te tonen, verder niets!procedure TFmain.btnTESTClick(Sender: TObject);begin  Showmessage(' YES button. ');end; procedure TFmain.btnSHOWpanelClick(Sender: TObject);begin    // = Panel op FMain zetten    Pan1 := TPanel.Create(Self);    with Pan1 do    begin      Parent := Fmain; // Moet de naam v.d. Form.      Left:= 30;      Top := 50;      Width := 500;      Height := 250;      Color:= clYellow;      Caption:= ' Make your choice ';      Show;      // =  Label op Panl zetten      lblTEXT:=TLabel.Create(self);      with lblTEXT do      begin        Parent := Pan1;        Left:= 33;        Top:=  23;        Font.Size:= 14;        Font.Name:= 'arial';        Font.Style:= [fsBold];        Font.Color:= clYellow;        Font.Style:= [fsBold];        Caption:= ' T E X T !';      end;      // = BUTTONJAPRINT op Panl zetten      btnJAPRINT:=TSpeedbutton.Create(self);      with btnJAPRINT do      begin        Parent := Pan1;        Caption := ' YES ';        Left := 30;        Top := 100;        Width := 100;        Height := 70;        Cursor:= crHandPoint;        font.Name:= 'arial';        font.Size:= 13;        font.Style:= [fsBold];        font.Color:= clRed;        // OnClick heeft een eigen proc. nodig.        OnClick := @btnTESTClick;      end;      // = BUTTONNEENPRINT op Panl zetten      btnNEENPRINT:=TSpeedbutton.Create(self);      with btnNEENPRINT do      begin        Parent := Pan1;        Caption := ' CLOSE ';        Left := 350;        Top := 100;        Width := 100;        Height := 70;        Cursor:= crHandPoint;        font.Name:= 'arial';        font.Size:= 13;        font.Style:= [fsBold];        font.Color:= clBlack;        // Bij klikken op de "btnNEENPRINT" wordt het Paneel verwijderd via de eigen proc.        // OnClick heeft een eigen proc. nodig.        OnClick:= @AnotherButtonClick;      end;    end; end; procedure TFmain.brnEXITClick(Sender: TObject);begin  Application.Terminate;end; end. 

winni:
Hi!

I think you confuse the compiler with the use of nested with

Close the with of the panel before you start the next with for the label.

Winni

howardpc:
try this:

--- Code: Pascal  [+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i < x.length; i++) { x[i].style.maxHeight='none'; x[i].style.height = Math.min(x[i].clientHeight+15,306)+'px'; x[i].style.resize = "vertical";}};} ---unit Unit1; {$mode objfpc}{$H+} interface uses  Classes, SysUtils, Forms, Controls, Graphics, Dialogs, StdCtrls, Buttons, ExtCtrls; type  TFmain = class(TForm)    btnShowPanel: TButton;    btnExit: TSpeedButton;    procedure btnExitClick(Sender: TObject);    procedure btnShowPanelClick(Sender: TObject);  private    Pan1: TPanel;    lblTEXT: TLabel;    btnJAPRINT: TSpeedButton;    btnNEENPRINT: TSpeedButton;    procedure AnotherButtonClick(Sender: TObject);    procedure btnTESTClick(Sender: TObject);  end; var  Fmain: TFmain; implementation {$R *.lfm} { TFmain } procedure TFmain.AnotherButtonClick(Sender: TObject);begin  ShowMessage('TFmain.AnotherButtonClick');end; procedure TFmain.btnTESTClick(Sender: TObject);begin  ShowMessage('TFmain.btnTESTClick');end; procedure TFmain.btnExitClick(Sender: TObject);begin  Close;end; procedure TFmain.btnShowPanelClick(Sender: TObject);begin  Pan1 := TPanel.Create(Self);  with Pan1 do begin    Left:= 30;    Top := 50;    Width := 500;    Height := 250;    Color:= clYellow;    Caption:= ' Make your choice ';    Parent := Self;  end;   lblTEXT := TLabel.Create(Self);  with lblTEXT do begin    Left:= 33;    Top:=  23;    Font.Size:= 14;    Font.Name:= 'arial';    Font.Style:= [fsBold];    Font.Color:= clYellow;    Font.Style:= [fsBold];    Caption:= ' T E X T !';    Parent := Pan1;  end;   btnJAPRINT := TSpeedbutton.Create(Self);  with btnJAPRINT do begin    Caption := ' YES ';    Left := 30;    Top := 100;    Width := 100;    Height := 70;    Cursor:= crHandPoint;    font.Name:= 'arial';    font.Size:= 13;    font.Style:= [fsBold];    font.Color:= clRed;    OnClick  := @btnTESTClick;    Parent := Pan1;  end;   btnNEENPRINT := TSpeedbutton.Create(Self);  with btnNEENPRINT do begin    Caption := ' CLOSE ';    Left := 350;    Top := 100;    Width := 100;    Height := 70;    Cursor:= crHandPoint;    font.Name:= 'arial';    font.Size:= 13;    font.Style:= [fsBold];    font.Color:= clBlack;    OnClick := @AnotherButtonClick;    Parent := Pan1;  end;end; end.

jamie:

--- Quote from: winni on October 02, 2021, 01:37:40 pm ---Hi!

I think you confuse the compiler with the use of nested with

Close the with of the panel before you start the next with for the label.

Winni

--- End quote ---

It seems I remember back in the old Delphi days there was a way to obtain the Object pointer within a WITH statement of the current WITH so that it could be used also inside the Block.

 I would need to investigate how that was done.

jamie:
I found my code frag I used in my Delphi code, Looking at it and seeing how fpc generates code I don't think it will work with fpc..

Have a good day.

Navigation

[0] Message Index

[#] Next page

Go to full version