Recent

Author Topic: Anyone know how to change the properties of 32 SlideBars from one proceedure  (Read 1448 times)

Thaddy

  • Hero Member
  • *****
  • Posts: 12972
That is the wrong approach. Seriously, do it like my example. How many more stupid answers we get, how many more beginners questions we have to answer.  >:D >:D >:D >:D  O:-) :-*
« Last Edit: April 01, 2023, 03:49:02 pm by Thaddy »
I actually get compliments for being rude... (well, Dutch, but that is the same)

dseligo

  • Hero Member
  • *****
  • Posts: 984
That is the wrong approach. Seriously, do it like my example. How many more stupid answers we get, how many more beginners questions we have to answer.  >:D >:D >:D >:D  O:-) :-*

OK, I made test project with 32 ECsliders.

Please show how would you change their styles using Sender when pressing one of the buttons.

Paolo

  • Sr. Member
  • ****
  • Posts: 382
Quote
Please show how would you change their styles using Sender when pressing one of the buttons.
I'm curious too

wp

  • Hero Member
  • *****
  • Posts: 10856
That is the wrong approach. Seriously, do it like my example.
You only showed pseudo-code, unrelated to the question.

Blaazen

  • Hero Member
  • *****
  • Posts: 3234
  • POKE 54296,15
    • Eye-Candy Controls
Hi,

I hope ECSliders will work well for you. I assume you design some equalizer or so.
I'd group them on panel and use:
Code: Pascal  [Select][+][-]
  1. var i: Integer;
  2. begin
  3.   for i:=0 to Panel1.ControlCount-1 do
  4.     if Panel1.Controls[i] is TECSlider then
  5.       with TECSlider(Panel1.Controls[i]) do
  6.         begin
  7.           BeginUpdate;
  8.           //do the job here
  9.           EndUpdate();
  10.         end;
Definitely use the BeginUpdate - EndUpdate pair. It will reduce many recalculation (4 per slider).
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/

Josh

  • Hero Member
  • *****
  • Posts: 1082
demo attached

10 sliders / faders created like an eq, timer animated them, start stop reset button.
sliders/faders called by name, with some safety checks.

added project unit code below, fo those without tecslider installed

Code: Pascal  [Select][+][-]
  1. unit Unit1;
  2.  
  3. {$mode objfpc}{$H+}
  4.  
  5. interface
  6.  
  7. uses
  8.   Classes, SysUtils, Forms, Controls, Graphics, Dialogs, StdCtrls, ExtCtrls,
  9.   ECSlider;
  10.  
  11. type
  12.  
  13.   { TForm1 }
  14.  
  15.   TForm1 = class(TForm)
  16.     btn_start: TButton;
  17.     btn_stop: TButton;
  18.     btn_reset: TButton;
  19.     ECSlider_EQ1: TECSlider;
  20.     ECSlider_EQ10: TECSlider;
  21.     ECSlider_EQ2: TECSlider;
  22.     ECSlider_EQ3: TECSlider;
  23.     ECSlider_EQ4: TECSlider;
  24.     ECSlider_EQ5: TECSlider;
  25.     ECSlider_EQ6: TECSlider;
  26.     ECSlider_EQ7: TECSlider;
  27.     ECSlider_EQ8: TECSlider;
  28.     ECSlider_EQ9: TECSlider;
  29.     Timer1: TTimer;
  30.     procedure btn_resetClick(Sender: TObject);
  31.     procedure btn_startClick(Sender: TObject);
  32.     procedure btn_stopClick(Sender: TObject);
  33.     procedure FormCreate(Sender: TObject);
  34.     procedure Timer1Timer(Sender: TObject);
  35.   private
  36.  
  37.   public
  38.  
  39.   end;
  40.  
  41. var
  42.   Form1: TForm1;
  43.   EQ_Animate:Boolean=False;
  44.   Eq_Reset:Boolean=True;
  45.  
  46. implementation
  47.  
  48. {$R *.lfm}
  49.  
  50. { TForm1 }
  51.  
  52. procedure TForm1.Timer1Timer(Sender: TObject);
  53. Const Eq_Name='ECSlider_EQ';
  54. Loop:Integer=1;
  55. begin
  56.   If ((EQ_Animate) or (Eq_Reset)) then   // only run code if animating or resettting
  57.   begin
  58.     // As We have created and named them we can assume they are TECSlider
  59.     Loop:=1;
  60.     While Findcomponent(Eq_Name+InttoStr(Loop))<>Nil Do
  61.     begin
  62.       // If you want an additional Safety Check then Add
  63.       // If Findcomponent(Eq_Name+InttoStr(Loop)) is TECSlider then
  64.       With Findcomponent(Eq_Name+InttoStr(Loop)) as TECSlider Do
  65.       Begin
  66.         BeginUpdate;
  67.         if EQ_Animate then position:=round(Random(round(Max)));
  68.         if Eq_Reset then position:=60;
  69.         EndUpDate;
  70.       end;
  71.       Inc(Loop);
  72.     end;
  73.     Eq_Reset:=False;
  74.     Application.ProcessMessages;  // process messageswill only be called if code is run.
  75.   end;
  76.  
  77. end;
  78.  
  79. procedure TForm1.btn_startClick(Sender: TObject);
  80. begin
  81.   EQ_Animate:=True;
  82. end;
  83.  
  84. procedure TForm1.btn_resetClick(Sender: TObject);
  85. begin
  86.   EQ_Animate:=false;
  87.   Eq_Reset:=True;
  88. end;
  89.  
  90. procedure TForm1.btn_stopClick(Sender: TObject);
  91. begin
  92.   EQ_Animate:=False;
  93. end;
  94.  
  95. procedure TForm1.FormCreate(Sender: TObject);
  96. begin
  97.   Randomize;
  98. end;
  99.  
  100. end.  

may hellp
« Last Edit: April 01, 2023, 04:45:10 pm by Josh »
The best way to get accurate information on the forum is to post something wrong and wait for corrections.

jamie

  • Hero Member
  • *****
  • Posts: 5344
That is the wrong approach. Seriously, do it like my example. How many more stupid answers we get, how many more beginners questions we have to answer.  >:D >:D >:D >:D  O:-) :-*

 Thaddy the smoking jerk.

 I know for a fact that what I suggested works because I've done it a few times.

 All I see here is massive, bloated code and those that will defend their idea to the ends of the earth, even if it takes everyone with them.

 I am glad I still have choices to use my own methods to reduce code glut with increases performance.

@Thaddy on the other hand: If it still does not work, just add some more non working code on top of the existing bloat that he tries to push on everyone.

  What a place, it's almost as bad as the local pub after work stop off.
The only true wisdom is knowing you know nothing

andyf97

  • New Member
  • *
  • Posts: 19
That is what I have done so far but its really complicated with some fields changed by value and some other by text:

     TickmarkStyle:=etsSolid;
     Width:=40;

There loads of parameters for the ECSliders, maybe 50. So what I want to do is have one of them like master settings that the rest follow, a bit learning curve to do. 



put all the controls inside of a TFlowPanel.

From there, you have a list of controls that you can step through via the ControlList property.

etc.

jamie

  • Hero Member
  • *****
  • Posts: 5344
if Implemented, and I can't say if it is or not, the ECSlider.Assign(From_Another_ECSlider); should cover most of the settings.

 After each one however, you'll most likely need to touch up the LEFT,TOP of the control so it doesn't overlap.
The only true wisdom is knowing you know nothing

Blaazen

  • Hero Member
  • *****
  • Posts: 3234
  • POKE 54296,15
    • Eye-Candy Controls
No, none of EC-Controls have implemented Assign.
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/

andyf97

  • New Member
  • *
  • Posts: 19
Thanks Jamie,

How does that assign work, I cannot find info about it.

if Implemented, and I can't say if it is or not, the ECSlider.Assign(From_Another_ECSlider); should cover most of the settings.

 After each one however, you'll most likely need to touch up the LEFT,TOP of the control so it doesn't overlap.

Blaazen

  • Hero Member
  • *****
  • Posts: 3234
  • POKE 54296,15
    • Eye-Candy Controls
Assign, if implemented, copies properties or fields of one instance of class to another. It does not have to be trivial, look for example to TFont.Assign().
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/

cdbc

  • Sr. Member
  • ****
  • Posts: 492
    • http://www.cdbc.dk
Hi
If "TECSlider" is a descendant of TPersistent, then it implements the FPObserved interface...
If you are making one slider the "Master", then all you have to do, is implement an Observer class that implements the "FPObserver" interface (easy peasy, it's 1 method) and the "assign" method (which you'll have to write yourself, but only once) for each "Listening" ECSlider. On startup of your app, you create the observers and "Attach" them all to the "Master", and Vupti "Bob's your uncle".
Maybe something like this:
Code: Pascal  [Select][+][-]
  1.   { TObserver ~ observer pattern }  (* ATTENTION: {$INTERFACES CORBA} = no ref-count *)
  2.   TECObserver = class(TObject,IFPObserver)
  3.   protected
  4.     fActiveECSlider: TECSlider;
  5.     procedure Assign; { you'll get the "source" in aSender parameter }
  6.   public
  7.     constructor Create(const anActiveECSlider: TECSlider);
  8.     destructor Destroy; override;
  9.     Procedure FPOObservedChanged(aSender: TObject;Operation: TFPObservedOperation;Data: Pointer);
  10.     property ActiveECSlider: TECSlider read fActiveECSlider write fActiveECSlider;
  11.   end; { TECObserver }
  12.  
...Or maybe one observer with an array of ECSliders?!?
Hth - Regards Benny
« Last Edit: April 02, 2023, 07:52:35 am by cdbc »
If it ain't broke, don't fix it ;)

andyf97

  • New Member
  • *
  • Posts: 19
Dseligo, Yours absolutely does the job, I downloaded your example project that you kindly shared, it also compiles perfectly.

So I copied the code from 'your button 1' and placed it into one of my buttons 'button 2'.

I get instant compile errors, attached an image.

This likely indicates that something is wrong with wither my whole project, or Lazarus is miss-configured. I suspect my project is most likely

I am wondering if my Lazarus or EC-Controls is not installed/configured properly, I am actually having consistent issues with Lazarus since trying to edit an old application I made with Delphi3 in 1997. Actually I have a bunch of applications that I made over the years with VB3..6, Delphi3..10, Basic that I started to replicate in Lazarus.  So that I use one standard platform.


I would do it like this:

Code: Pascal  [Select][+][-]
  1. procedure TForm1.Button1Click(Sender: TObject);
  2. var i: Integer;
  3. begin
  4.   For i := 0 to Pred(ControlCount) do
  5.     If Controls[i] is TECSlider then
  6.       With (Controls[i] as TECSlider).Knob do begin
  7.         BevelWidth:=2;
  8.         Color:=clHighlight;
  9.         Cursor:=crHandpoint;
  10.         Height:=32;
  11.         Style := eosButton;
  12.         TickMarkCount:=1;
  13.         TickMarkDesign:=etdSimple;
  14.         TickmarkSpacing:=2;
  15.         TickmarkStyle:=etsSolid;
  16.         Width:=40;
  17.       end;
  18. end;
« Last Edit: April 02, 2023, 08:07:06 am by andyf97 »

af0815

  • Hero Member
  • *****
  • Posts: 1205
search where eosButton, edtSimple and etsSolid is defined. Such an error is normal you only have not all needed units bound.
regards
Andreas

 

TinyPortal © 2005-2018