Login ProductsSalesSupportDownloadsAbout |
Home » Technical Support » Elevate Web Builder Technical Support » Support Forums » Elevate Web Builder General » View Thread |
Messages 1 to 10 of 10 total |
create TPanel with Array |
Sun, Mar 6 2016 10:47 AM | Permanent Link |
Riaz | Hi,
i am trying to create 4 TPanels with an Array what i would like is to create a Tpanel with Timage within it could someone please help me with some basic code what i have done so far is thank you, Riaz public apan :array of TPanel; procedure TMainForm.Button1Click(Sender: TObject); var I: Integer; begin ScrollPanel1.BeginUpdate; try for I:=1 to 4 do begin apan[I]:= TPanel.Create(ScrollPanel1); apan[I].Animations.Visible.Duration:=400; apan[I].Animations.Visible.Style:=asQuadEaseOut; apan[I].Animations.Height.Duration:=400; apan[I].Animations.Height.Style:=asQuadEaseOut; apan[I].Animations.Left.Duration:=400; apan[I].Animations.Left.Style:=asQuadEaseOut; apan[I].Animations.Top.Duration:=400; apan[I].Animations.Top.Style:=asQuadEaseOut; apan[I].Layout.Position:=lpTopLeft; apan[I].Layout.Consumption:=lcRight; apan[I].Layout.Overflow:=loBottom; apan[I].Background.Fill.Color:=clElevateLightOrange; apan[I].CaptionBar.Background.Fill.Color:=clElevateOrange; apan[I].CaptionBar.Caption:='panel'+IntToStr(I); apan[I].CaptionBar.AllowMinimize:=True; apan[I].CaptionBar.AllowMove:=False; apan[I].Width:=100; apan[I].Height:=100; apan[I].Margins.Left:=5; apan[I].Margins.Top:=5; end; finally ScrollPanel1.EndUpdate; end; end; |
Sun, Mar 6 2016 4:12 PM | Permanent Link |
Raul Team Elevate | On 3/6/2016 10:47 AM, Riaz wrote:
> what i would like is to create a Tpanel with Timage within it > could someone please help me with some basic code What exactly are you having problems with ? > what i have done so far is > apan :array of TPanel; Are you actually initializing this array somewhere else ? since it's dynamic you need to do so by calling SetLength(apan,4); before you start using it (for example before the "for" loop in the code you have. Otherwise the code you have works fine and lays our 4 panels inside a scrollpanel. You'd still need to also create the Timage objects though. Something like this (your code with some small additions) works here : procedure TForm1.Button1Click(Sender: TObject); var apan :array of TPanel; ti:TImage; i:integer; begin SetLength(apan,4); ScrollPanel1.BeginUpdate; for I:=1 to 4 do begin apan[I]:= TPanel.Create(ScrollPanel1); apan[I].Animations.Visible.Duration:=400; apan[I].Animations.Visible.Style:=asQuadEaseOut; apan[I].Animations.Height.Duration:=400; apan[I].Animations.Height.Style:=asQuadEaseOut; apan[I].Animations.Left.Duration:=400; apan[I].Animations.Left.Style:=asQuadEaseOut; apan[I].Animations.Top.Duration:=400; apan[I].Animations.Top.Style:=asQuadEaseOut; apan[I].Layout.Position:=lpTopLeft; apan[I].Layout.Consumption:=lcRight; apan[I].Layout.Overflow:=loBottom; apan[I].Background.Fill.Color:=clElevateLightOrange; apan[I].CaptionBar.Background.Fill.Color:=clElevateOrange; apan[I].CaptionBar.Caption:='panel'+IntToStr(I); apan[I].CaptionBar.AllowMinimize:=True; apan[I].CaptionBar.AllowMove:=False; apan[I].Width:=150; apan[I].Height:=100; apan[I].Margins.Left:=5; apan[I].Margins.Top:=5; //create image ti := TImage.Create(apan[I]); ti.Layout.Position := lpTopleft; ti.Layout.Stretch := lsBottomRight; ti.URL := 'earth-icon.png'; end; ScrollPanel1.EndUpdate; end; |
Sun, Mar 6 2016 5:02 PM | Permanent Link |
Riaz | Raul,
Thank you i missed the SetLength(apan,4); thank you so much Riaz |
Mon, Mar 7 2016 5:01 AM | Permanent Link |
Matthew Jones | Riaz wrote:
> SetLength(apan,4); FWIW, if you are going to do something more with those panels, like remove them later, you'd be better off adding them to a TObjectList which is a member of the form. You then don't need to manage the array size. -- Matthew Jones |
Mon, Mar 7 2016 6:10 AM | Permanent Link |
Riaz | "Matthew Jones" wrote:
Riaz wrote: > SetLength(apan,4); FWIW, if you are going to do something more with those panels, like remove them later, you'd be better off adding them to a TObjectList which is a member of the form. You then don't need to manage the array size. -- Matthew Jones Thank you Matthew, great to learn new things, thank you Riaz |
Mon, Mar 7 2016 6:50 AM | Permanent Link |
Riaz | "Matthew Jones" wrote:
Riaz wrote: > SetLength(apan,4); FWIW, if you are going to do something more with those panels, like remove them later, you'd be better off adding them to a TObjectList which is a member of the form. You then don't need to manage the array size. -- Matthew Jones Hi Matthew, do you have a small example of how to use the TObjectList so panels can be created and removed, like shopping cart list thank you, Riaz |
Mon, Mar 7 2016 7:42 AM | Permanent Link |
Matthew Jones | Riaz wrote:
> Hi Matthew, do you have a small example of how to use the TObjectList > so panels can be created and removed, like shopping cart list In the form: private m_xProductDisplay : TObjectList; procedure TfrmShop.frmShopCreate(Sender: TObject); begin m_xProductDisplay := TObjectList.Create(true); .... procedure TfrmShop.frmShopDestroy(Sender: TObject); begin m_xProductDisplay.Free; .... procedure TfrmShop.CreatePanelFor; var xPanel : TPanel; begin xPanel := TPanel.Create(); nIndex := m_xProductDisplay.Add(xPanel); xPanel.Tag := nIndex; // allow it to be identified in code ... end; // clear items (do this before you reload the list) m_xProductDisplay.Clear; Note that the TObjectList.OwnsObjects property determines if the Clear will free the objects. I think the default is true but the documentation doesn't say so. Hmm, the code says otherwise, so I presume it is default to FALSE. I have modified my code (and the example above) to set True in the Create. -- Matthew Jones |
Mon, Mar 7 2016 8:17 AM | Permanent Link |
Riaz | Hi Matthew,
thank you so much, i really appreciate this Riaz |
Mon, Mar 7 2016 8:46 AM | Permanent Link |
Tim Young [Elevate Software] Elevate Software, Inc. timyoung@elevatesoft.com | Matthew,
<< Note that the TObjectList.OwnsObjects property determines if the Clear will free the objects. I think the default is true but the documentation doesn't say so. Hmm, the code says otherwise, so I presume it is default to FALSE. I have modified my code (and the example above) to set True in the Create. >> Hmm, this should be true, by default, so I'll make sure to add this as a breaking change in 2.05. Tim Young Elevate Software www.elevatesoft.com |
Mon, Mar 7 2016 9:14 AM | Permanent Link |
Matthew Jones | Tim Young [Elevate Software] wrote:
> Hmm, this should be true, by default, so I'll make sure to add this > as a breaking change in 2.05. That would be good - I checked the v1 source too, and it is not set (which I presume is therefore False). -- Matthew Jones |
This web page was last updated on Monday, October 14, 2024 at 05:15 PM | Privacy PolicySite Map © 2024 Elevate Software, Inc. All Rights Reserved Questions or comments ? E-mail us at info@elevatesoft.com |