Icon View Thread

The following is the text of the current message along with any replies.
Messages 1 to 10 of 13 total
Thread onclick runtime for tpanel create runtime
Mon, Mar 14 2016 6:11 AMPermanent Link

Pasquale

Web Pos srl

i have this code (example panels)

  ScrollPanel1.BeginUpdate;
  try
     for I:=1 to 7 do
        begin
        with TPanel.Create(ScrollPanel1) do
           begin
           Animations.Visible.Duration:=400;
           Animations.Visible.Style:=asQuadEaseOut;
           Animations.Height.Duration:=400;
           Animations.Height.Style:=asQuadEaseOut;
           Animations.Left.Duration:=400;
           Animations.Left.Style:=asQuadEaseOut;
           Animations.Top.Duration:=400;
           Animations.Top.Style:=asQuadEaseOut;
           Layout.Position:=lpTopLeft;
           Layout.Consumption:=lcRight;
           Layout.Overflow:=loBottom;
           Background.Fill.Color:=clWhite;
           CaptionBar.Background.Fill.Color:=clSkyBlue;
           CaptionBar.Padding.Left := 0;
           Background.Image.RepeatStyle  := rsNone;
           Background.Image.PositionType := ptCenterCenter;
           Background.Image.SizeType     := stContain;

           IF i = 1 Then
           Begin
             CaptionBar.Caption    :='Ricariche OnLine';
             Background.Image.Name :='operatori.jpg';
             Name                  :='ricaricheonline';
             //OnClick               := clickricariche(nil);
           End
           Else
           IF i = 2 Then
           Begin
             CaptionBar.Caption    :='Ricariche Pin';
             Background.Image.Name :='ricariche.jpg';
             Name                  :='ricarichepin';
           End
           Else
           IF i = 3 Then
           Begin
             CaptionBar.Caption:='Pagamento Bollettini';
           End
           Else
           IF i = 4 Then
           Begin
             CaptionBar.Caption:='Visure';
           End
           Else
           IF i = 5 Then
           Begin
             CaptionBar.Caption:='Ricariche Internazionali';
           End
           Else
           IF i = 6 Then
           Begin
             CaptionBar.Caption:='Ricariche PostePay';
           End
           Else
           IF i = 7 Then
           Begin
             CaptionBar.Caption:='Spedizioni';
           End;


           CaptionBar.AllowMinimize   := False;
           CaptionBar.AllowMove       := False;
           CaptionBar.AllowClose      := False;
           Border.Left.Visible        := True;
           Border.Left.Color          := clLightGray;
           Border.Right.Visible       := True;
           Border.Right.Color         := clLightGray;
           Border.Bottom.Visible      := True;
           Border.Bottom.Color        := clLightGray;
           Border.Top.Visible         := True;
           Border.Top.Color           := clLightGray;
           CaptionBar.Font.Style.Bold := True;
           CaptionBar.Font.Size       := 16;
           Width                      := 200;
           Height                     := 200;
           Margins.Left               := 60;
           Margins.Top                := 60;
           Cursor                     := crPointer;
           end;
        end;
  finally
     ScrollPanel1.EndUpdate;
  end;


HOW CAN I DO ASSIGN THE EVENT ONCLICK FOR THE PANEL CREATE AT RUN-TIME ?
Mon, Mar 14 2016 6:35 AMPermanent Link

squiffy

Telemix Ltd.

Avatar

>> HOW CAN I DO ASSIGN THE EVENT ONCLICK FOR THE PANEL CREATE AT RUN-TIME ?

What happens when you just assign the OnClick event to a procedure? As long as it's defined like this :

procedure myclick(Sender : TObject);

and implemented like this :

procedure TmyForm.myclick(Sender : TObject);
begin
   showmessage('clicked');
end;

then
   mypanel.OnClick := myclick;

*should* work.
Mon, Mar 14 2016 6:42 AMPermanent Link

squiffy

Telemix Ltd.

Avatar

I missed this in your example :
  //OnClick               := clickricariche(nil);

Just do
   OnClick := clickricariche;

and define "clickricariche" as I wrote above. That will work.
Mon, Mar 14 2016 6:43 AMPermanent Link

Pasquale

Web Pos srl

Not function .... attach the complete code

unit Main;

interface

uses WebCore, WebUI, WebForms, WebCtrls, WebCtnrs, WebLabels, WebIcons, WebBtns, WebSizer,
  WebBrwsr, WebSlide;

type

  TMainForm = class(TForm)
     HeaderPanel1: THeaderPanel;
     Label51: TLabel;
     CreatePanel: TBasicPanel;
     Button1: TButton;
     ScrollPanel1: TScrollPanel;
     Button2: TButton;
     Button3: TButton;
     Image1: TImage;
     Panel1: TPanel;
     Label1: TLabel;
     Label2: TLabel;
     Label3: TLabel;
     Label4: TLabel;
     SlideShow1: TSlideShow;
     procedure Button1Click(Sender: TObject);
     procedure clickricaricheonline(Sender : TObject);
  private
     { Private declarations }
  public
     { Public declarations }
  end;

var
  MainForm: TMainForm;

implementation

procedure clickricaricheonline(Sender : TObject);
Begin
 showmessage('clicked');
End;

procedure TMainForm.Button1Click(Sender: TObject);
var
  I: Integer;
begin      
  ScrollPanel1.BeginUpdate;
  try
     for I:=1 to 7 do
        begin
        with TPanel.Create(ScrollPanel1) do
           begin
           Animations.Visible.Duration:=400;
           Animations.Visible.Style:=asQuadEaseOut;
           Animations.Height.Duration:=400;
           Animations.Height.Style:=asQuadEaseOut;
           Animations.Left.Duration:=400;
           Animations.Left.Style:=asQuadEaseOut;
           Animations.Top.Duration:=400;
           Animations.Top.Style:=asQuadEaseOut;
           Layout.Position:=lpTopLeft;
           Layout.Consumption:=lcRight;
           Layout.Overflow:=loBottom;
           Background.Fill.Color:=clWhite;
           CaptionBar.Background.Fill.Color:=clSkyBlue;
           CaptionBar.Padding.Left := 0;
           Background.Image.RepeatStyle  := rsNone;
           Background.Image.PositionType := ptCenterCenter;
           Background.Image.SizeType     := stContain;

           IF i = 1 Then
           Begin
             CaptionBar.Caption    :='Ricariche OnLine';
             Background.Image.Name :='ricariche.jpg';
             Name                  :='ricaricheonline';
             OnClick               :=clickricaricheonline;
           End
           Else
           IF i = 2 Then
           Begin
             CaptionBar.Caption    :='Ricariche Pin';
             Background.Image.Name :='ricariche.jpg';
             Name                  :='ricarichepin';
           End
           Else
           IF i = 3 Then
           Begin
             CaptionBar.Caption:='Pagamento Bollettini';
           End
           Else
           IF i = 4 Then
           Begin
             CaptionBar.Caption:='Visure';
           End
           Else
           IF i = 5 Then
           Begin
             CaptionBar.Caption:='Ricariche Internazionali';
           End
           Else
           IF i = 6 Then
           Begin
             CaptionBar.Caption:='Ricariche PostePay';
           End
           Else
           IF i = 7 Then
           Begin
             CaptionBar.Caption:='Spedizioni';
           End;


           CaptionBar.AllowMinimize   := False;
           CaptionBar.AllowMove       := False;
           CaptionBar.AllowClose      := False;
           Border.Left.Visible        := True;
           Border.Left.Color          := clLightGray;
           Border.Right.Visible       := True;
           Border.Right.Color         := clLightGray;
           Border.Bottom.Visible      := True;
           Border.Bottom.Color        := clLightGray;
           Border.Top.Visible         := True;
           Border.Top.Color           := clLightGray;
           CaptionBar.Font.Style.Bold := True;
           CaptionBar.Font.Size       := 16;
           Width                      := 200;
           Height                     := 200;
           Margins.Left               := 60;
           Margins.Top                := 60;
           Cursor                     := crPointer;
           end;
        end;
  finally
     ScrollPanel1.EndUpdate;
  end;
end;

end.
Mon, Mar 14 2016 6:47 AMPermanent Link

Michael Dreher

Pasquale wrote:

 /// i have this code (example panels)
 /// HOW CAN I DO ASSIGN THE EVENT ONCLICK FOR THE PANEL CREATE AT RUN-TIME ?

You need a predefined event handler, then you can assign it to the OnClick property like this:

type
  TForm1 = class(TForm)
     Label1: TLabel;
     ScrollPanel1: TScrollPanel;
     procedure Form1Show(Sender: TObject);
  private
     procedure OnClickHandler(sender : TObject);
  end;

var
  Form1: TForm1;

implementation

procedure TForm1.OnClickHandler(sender : TObject);
begin      
 ShowMessage('In the  OnClick handler...');
end;

procedure TForm1.Form1Show(Sender: TObject);    
var panel : TPanel;
begin    
 panel := TPanel.Create(ScrollPanel1);    
 panel.OnClick := OnClickHandler;
end;

Michael Dreher
Mon, Mar 14 2016 6:51 AMPermanent Link

squiffy

Telemix Ltd.

Avatar

This :

procedure clickricaricheonline(Sender : TObject);
Begin
showmessage('clicked');
End;

Needs to be this (note the TMainForm):

procedure  TMainForm.clickricaricheonline(Sender : TObject);
Begin
showmessage('clicked');
End;
Mon, Mar 14 2016 6:58 AMPermanent Link

Pasquale

Web Pos srl

ok function .

I would always create a run-time the SLIDESHOW into TPANEL (create at RUN-TIME) . It's possible ?

How should i do ?


Tanks .
Mon, Mar 14 2016 7:19 AMPermanent Link

squiffy

Telemix Ltd.

Avatar

Not sure I fully understand your question, but as a guess -

you can create objects "inside" others at runtime by setting the Parent property. Example (pseudocode, not tested) :

var panel : TPanel;
var button : TButton;

panel := TPanel.Create;
button := TButton.Create;

button.Parent := panel;

Is that what you meant?
Mon, Mar 14 2016 7:28 AMPermanent Link

Pasquale

Web Pos srl

           IF i = 1 Then
           Begin
             CaptionBar.Caption          :='Ricariche OnLine';
             Background.Image.Name :='ricariche.jpg';
             Name                                :='ricaricheonline';
             OnClick                             :=clickricaricheonline;

             with TSlideShow.Create(nil) do
             begin                     
               Parent               := ricaricheonline;
               Layout.Position := lpCenter;
               Width                 := 180;
               Height                := 180;
               Hint                    := 'Clicca qui';
               ImageURLs.Add('link site');
             end;

           End;



NOT exists var panel : TPanel  because i generated RUN-TIME and assigned name ricaricheonline



squiffy wrote:

Not sure I fully understand your question, but as a guess -

you can create objects "inside" others at runtime by setting the Parent property. Example (pseudocode, not tested) :

var panel : TPanel;
var button : TButton;

panel := TPanel.Create;
button := TButton.Create;

button.Parent := panel;

Is that what you meant?
Mon, Mar 14 2016 7:42 AMPermanent Link

squiffy

Telemix Ltd.

Avatar

You would either need to create a tobject array and loop through to find the object you require, or you can loop through the form's Component array - again this is pseudocode as I can't test right now :

for i := 0 to Form1.ComponentCount - 1 do
begin
  if (Component[i] is TPanel) then
     if Component[i].Tag = 1 then
          Component[i].Free;

end;

Might not be 100% correct but it shows the principle.
You could further check to see if it's name is the one you are looking for.

There are examples of TObject Array in the docs.
Page 1 of 2Next Page »
Jump to Page:  1 2
Image