Recent

Author Topic: BCButton - assign style at runtime - exception  (Read 2418 times)

mike_p

  • New Member
  • *
  • Posts: 16
BCButton - assign style at runtime - exception
« on: November 25, 2021, 08:47:47 pm »
I'm really liking bgra controls.
SO much so that I've started building my own style editor, but when I try to load (assign?) a style at runtime, I get an exception.
For example I try to load lainz.bcbtn style using BCButton1.loadfromfile or BCButton1.assignFromFile and neither work.
I know that I've got the correct path because I'm reading from and writing to the correct path.
What could I be doing wrong?

mike_p

  • New Member
  • *
  • Posts: 16
Re: BCButton - assign style at runtime - exception
« Reply #1 on: November 25, 2021, 08:58:37 pm »
Have also now found this topic that appears to have the same problem, but definitely not solved.
https://forum.lazarus.freepascal.org/index.php/topic,51589.0.html
BTW on Windows 10 at the moment, may try on a 'nix box later.

winni

  • Hero Member
  • *****
  • Posts: 2857
Re: BCButton - assign style at runtime - exception
« Reply #2 on: November 25, 2021, 09:05:30 pm »
Hi!

That is not your problem but  problem of the BCButton. It is a bug and still not solved.

Work around:
Set all the (endless) properties of one Button to your needs.

Then copy the properties to all other BCbuttons with a procedure like this:

Code: Pascal  [Select][+][-]
  1.  
  2. procedure TForm1.InitBCButtons(master:TBCButton);
  3. var i : Integer;
  4. begin
  5. for i := 0 to ComponentCount - 1 do
  6.   begin
  7.   if (Components[i] is TBCButton) and (Components[i] <> master) then
  8.     begin
  9.     TBCButton(Components[i]).Rounding := master.Rounding;
  10.     TBCButton(Components[i]).StateHover := master.StateHover;
  11.     TBCButton(Components[i]).StateClicked := master.StateClicked;
  12.     TBCButton(Components[i]).StateNormal := master.StateNormal;
  13.    .....
  14.     end; // is TBCButton;
  15.   end; // i
  16. end;                            
  17.  

Winni

mike_p

  • New Member
  • *
  • Posts: 16
Re: BCButton - assign style at runtime - exception
« Reply #3 on: November 25, 2021, 09:14:22 pm »
Thanks for the reply! So it's not just me!

I actually made a set of styled components for Delphi 20 years ago but they didn't easily translate to fpc/Laz.
So delighted to find something fairly similar.

What I want to build now is a tool to create styles where the colour palette (hue) is shifted, say, 180degrees or 120 degrees, and all other properties the same.

Not sure whether trying to solve the bug myself is the best way forward OR hard code (as you suggested) all the individual properties.

winni

  • Hero Member
  • *****
  • Posts: 2857
Re: BCButton - assign style at runtime - exception
« Reply #4 on: November 25, 2021, 09:22:14 pm »
Hi!

You know about  HSLA and HSLAToBGRA()  in BGRAbitmap??

Winni

mike_p

  • New Member
  • *
  • Posts: 16
Re: BCButton - assign style at runtime - exception
« Reply #5 on: November 25, 2021, 09:25:37 pm »
You know about  HSLA and HSLAToBGRA()  in BGRAbitmap??

Simple answer: no I don't. But will have a look!

Though I still have my own HSV code that handles most of what I want.

Is there another bug in handling font sizes in TBCButton?

lainz

  • Hero Member
  • *****
  • Posts: 3884
Re: BCButton - assign style at runtime - exception
« Reply #6 on: November 25, 2021, 10:02:44 pm »
BCButton has SaveToJSON and LoadFromJSON, that's the one you must use. I prefer JSON because is human readable.

Also SaveToFile and LoadFromFile must work. But the IDE format is different, you can't use LoadFromFile with these.

mike_p

  • New Member
  • *
  • Posts: 16
Re: BCButton - assign style at runtime - exception
« Reply #7 on: November 25, 2021, 10:58:37 pm »
Thanks Lainz, I appreciate your input and work in this area.

So from what you say I need to import styles in their current format then export as Json?

As a format I like json.  I wrote a class to import the bcbutton format into a treeview. However I've already got a json to treeview component! So happy with this suggestion,

lainz

  • Hero Member
  • *****
  • Posts: 3884
Re: BCButton - assign style at runtime - exception
« Reply #8 on: November 25, 2021, 11:32:02 pm »
Thanks Lainz, I appreciate your input and work in this area.

So from what you say I need to import styles in their current format then export as Json?

As a format I like json.  I wrote a class to import the bcbutton format into a treeview. However I've already got a json to treeview component! So happy with this suggestion,

What I mean is that you can't import files generated with the IDE, like these in the folder styles.

If you place a button, assign the windows 10 style for example, then at runtime save as json, then you have the copy of that style generated by the IDE.

 

TinyPortal © 2005-2018