Recent

Author Topic: [REOPENED] EC Accordion  (Read 1945 times)

pcurtis

  • Hero Member
  • *****
  • Posts: 951
[REOPENED] EC Accordion
« on: August 02, 2020, 09:08:05 am »
Hi All,

anyone got any example code on how to use EC Accordion. The demo program is very basic.
I'm interested in nesting items and adding controls at runtime to an item.

Thanks in advance.
« Last Edit: August 03, 2020, 07:45:53 am by pcurtis »
Windows 10 20H2
Laz 2.2.0
FPC 3.2.2

Blaazen

  • Hero Member
  • *****
  • Posts: 3241
  • POKE 54296,15
    • Eye-Candy Controls
Re: EC Accordion
« Reply #1 on: August 02, 2020, 12:57:07 pm »
Adding items at runtime:
Code: Pascal  [Select][+][-]
  1. ECAccordion1.AddItem(self); //where [b]self[/b] is rather Form, because AccordionItems are TWinControl
You can for example set Height of opened item:
Code: Pascal  [Select][+][-]
  1. var aAI: TAccordionItem;
  2. begin
  3.   aAI:=ECAccordion1.AddItem(self);
  4.   aAI.PreferredHeight:=300;

As I mentioned, each item is TWinControl so you can put there whatever (including another TECAccordion) and you can anchor it.

Nesting:
Code: Pascal  [Select][+][-]
  1. ECAccordion2.Parent:=ECAccordion1.Item[0];
  2.   ECAccordion2.Left:=10;
  3.   ECAccordion2.Top:=10;
No matter if you create the second ECAccordion at desgntime or runtime.
Lazarus 2.3.0 (rev main-2_3-2863...) FPC 3.3.1 x86_64-linux-qt Chakra, Qt 4.8.7/5.13.2, Plasma 5.17.3
Lazarus 1.8.2 r57369 FPC 3.0.4 i386-win32-win32/win64 Wine 3.21

Try Eye-Candy Controls: https://sourceforge.net/projects/eccontrols/files/

pcurtis

  • Hero Member
  • *****
  • Posts: 951
Re: EC Accordion
« Reply #2 on: August 02, 2020, 01:56:31 pm »
Thanks, it's still not clear for me how to add controls at runtime  :(

I tried this

Code: Pascal  [Select][+][-]
  1. var
  2.   myb : TButton;
  3.   aAI: TAccordionItem;
  4. begin
  5.   aAI := ECAccordion1.AddItem(ECAccordion1);
  6.   aAI.PreferredHeight:=300;
  7.  
  8.   myb := TButton.Create(ECAccordion1.Item[0]);
  9.   myb.Visible:=true;
  10.   myb.Top:=0;
  11.   myb.Left:=0;
  12.   myb.Show;
  13.  
and it didn't work.

Also do I have to free my created objects or are they freed automatically?
« Last Edit: August 02, 2020, 03:10:21 pm by pcurtis »
Windows 10 20H2
Laz 2.2.0
FPC 3.2.2

jamie

  • Hero Member
  • *****
  • Posts: 6130
Re: EC Accordion
« Reply #3 on: August 02, 2020, 03:40:43 pm »
I've never used those controls but it looks simple to understand for me..

Item which really should of been named "Items" to indicate more than one of course, generates a new control for you by using addItem(TheOwner). The new control should be displaying on its parent by the looks of it.

 The owner is the one responsible for the clean up of the control when terminating.

 So I guess this control allows to add more of itself like a tree like form, meaning if you use the ITEM.AddItem(TheOwner) it will create a new control plus it also returns it at the same time so you can define the remaining properties.

 Of course you can create a totally independent control as a base too, as you are doing here obviously..

 I could install those controls to help you out if needed.


The only true wisdom is knowing you know nothing

Blaazen

  • Hero Member
  • *****
  • Posts: 3241
  • POKE 54296,15
    • Eye-Candy Controls
Re: EC Accordion
« Reply #4 on: August 02, 2020, 04:07:37 pm »
@ pcurtis

It does not work because you didn't set Button.Parent (constructor sets Owner).
Code: Pascal  [Select][+][-]
  1. var myb: TButton;
  2. begin
  3.   myb := TButton.Create(self);
  4.   myb.Parent:=ECAccordion1.Item[0];
  5.   myb.Top:=0;
  6.   myb.Left:=0;

@ jamie

I noticed it too. Item should be Items. Changing it now will make troubles for a unknown amount of developers, c'est la vie.
Lazarus 2.3.0 (rev main-2_3-2863...) FPC 3.3.1 x86_64-linux-qt Chakra, Qt 4.8.7/5.13.2, Plasma 5.17.3
Lazarus 1.8.2 r57369 FPC 3.0.4 i386-win32-win32/win64 Wine 3.21

Try Eye-Candy Controls: https://sourceforge.net/projects/eccontrols/files/

pcurtis

  • Hero Member
  • *****
  • Posts: 951
Re: EC Accordion
« Reply #5 on: August 02, 2020, 04:50:18 pm »
Success !

The following code works.

Code: Pascal  [Select][+][-]
  1. procedure TForm1.Button3Click(Sender: TObject);
  2. var
  3.   myb : TButton;
  4.   aAI: TAccordionItem;
  5. begin
  6.   aAI := ECAccordion1.AddItem(self);
  7.   aAI.PreferredHeight:=300;
  8.  
  9.   myb := TButton.Create(ECAccordion1);
  10.   myb.Parent:=  ECAccordion1.Item[aAI.Index];
  11.   myb.Visible:=true;
  12.   myb.Top:=10;
  13.   myb.Left:=10;
  14. end;
  15.  

but I have just on last question. In my above example how would I handle the OnClick event for my newley created button?
Thanks for your help. Great controls.
Windows 10 20H2
Laz 2.2.0
FPC 3.2.2

pcurtis

  • Hero Member
  • *****
  • Posts: 951
Re: EC Accordion
« Reply #6 on: August 02, 2020, 05:01:40 pm »
It's OK. I think I've got it.

Code: Pascal  [Select][+][-]
  1. procedure MyClick(Sender: TObject);
  2.  
  3. procedure TForm1.MyClick(Sender: TObject);
  4. begin
  5.   Beep;
  6. end;
  7.  
  8.  
  9. var
  10.   myb : TButton;
  11.   aAI: TAccordionItem;
  12. begin
  13.   aAI := ECAccordion1.AddItem(self);
  14.   aAI.PreferredHeight:=300;
  15.  
  16.   myb := TButton.Create(ECAccordion1);
  17.   myb.Parent:=  ECAccordion1.Item[aAI.Index];
  18.   myb.Visible:=true;
  19.   myb.Top:=10;
  20.   myb.Left:=10;
  21.   myb.OnClick:=@MyClick;
  22.  
  23.  
  24.  
Windows 10 20H2
Laz 2.2.0
FPC 3.2.2

pcurtis

  • Hero Member
  • *****
  • Posts: 951
Re: [SOLVED] EC Accordion
« Reply #7 on: August 03, 2020, 07:45:10 am »
@Jamie

Quote
I could install those controls to help you out if needed.

Sorry Jamie, was you offer directed to me or Blaazen?
Windows 10 20H2
Laz 2.2.0
FPC 3.2.2

jamie

  • Hero Member
  • *****
  • Posts: 6130
Re: [SOLVED] EC Accordion
« Reply #8 on: August 03, 2020, 10:40:46 pm »
@Jamie

Quote
I could install those controls to help you out if needed.

Sorry Jamie, was you offer directed to me or Blaazen?

Well I think it was directed to you but I guess you have some working code so you should be ok...

Btw, you don't need to Re-Index for the newly created control because it has been set locally for you already.

Code: Pascal  [Select][+][-]
  1.  myb.Parent:=  ECAccordion1.Item[aAI.Index];
  2.  

You should be able to do this..
Code: Pascal  [Select][+][-]
  1.  myb.Parent:= aAI;
  2.  

The only true wisdom is knowing you know nothing

 

TinyPortal © 2005-2018