Recent

Author Topic: BCButton crashes while LoadFromFile  (Read 1317 times)

winni

  • Hero Member
  • *****
  • Posts: 3197
BCButton crashes while LoadFromFile
« on: September 27, 2020, 09:04:49 pm »
Hi!

I try to assign a button design from the styles directory at runtime to a BCButton.

This results in a crash.  See attachment.

LoadFromFile calls somewhere a stream and that stream tries to find the token, but it finds the first char which is a '['. The stream does not like that.

Is there a workaround?

Winni




lainz

  • Hero Member
  • *****
  • Posts: 4460
    • https://lainz.github.io/
Re: BCButton crashes while LoadFromFile
« Reply #1 on: September 27, 2020, 10:59:03 pm »
These are not in the same format if I remember correctly.

Try saving to file a BCButton you designed with the inspector at runtime. Then try loading it, it works?

winni

  • Hero Member
  • *****
  • Posts: 3197
Re: BCButton crashes while LoadFromFile
« Reply #2 on: September 27, 2020, 11:11:07 pm »
Hi!

I tested that and saw that it is a different format.
But LoadFromFile gives the same error message:

It cannot find the token, but finds a char.

Winni

lainz

  • Hero Member
  • *****
  • Posts: 4460
    • https://lainz.github.io/
Re: BCButton crashes while LoadFromFile
« Reply #3 on: September 28, 2020, 12:04:58 am »
Seems a bug, but not in BGRAControls, the streaming is as you can see in the code with some FPC stuff.

Also the loading from JSON doesn't works, and it was working fine before 3.2...

I'm adding a bug report in bgracontrols to further investigate, but I've not changed anything and stopped working, so maybe a bug in FPC.

lainz

  • Hero Member
  • *****
  • Posts: 4460
    • https://lainz.github.io/
Re: BCButton crashes while LoadFromFile
« Reply #4 on: September 28, 2020, 12:14:58 am »
Try this:

Code: Pascal  [Select][+][-]
  1.   BCButton1.SaveToFile('button.bcbtn');
  2.   BCButton2.AssignFromFile('button.bcbtn');

It works. Is AssignFromFile what you need to call. I don't remember why I choose that naming...

But this JSON loading doesn't works, I'm not sure why, it was working, but on 3.0.4 and 3.2 doesn't work anymore.  :(

Code: Pascal  [Select][+][-]
  1.   BCButton1.SaveToJSON('button.bcbtn');
  2.   BCButton2.LoadFromJSON('button.bcbtn');    
« Last Edit: September 28, 2020, 12:18:50 am by lainz »

winni

  • Hero Member
  • *****
  • Posts: 3197
Re: BCButton crashes while LoadFromFile
« Reply #5 on: September 28, 2020, 01:25:29 am »
Hi!

The example with AssignFile works! Thanx.

But how to load the predifined *.btbtn files in the directory styles ??


And about the naming of AssignFile:

We call now the fork a spoon.
And the spoon we call hammer.

To much Monty Python???

Winni

lainz

  • Hero Member
  • *****
  • Posts: 4460
    • https://lainz.github.io/
Re: BCButton crashes while LoadFromFile
« Reply #6 on: September 28, 2020, 01:50:01 am »
The LoadFromFile is used internally, it should be private.  ::)

To load the predefined styles, you maybe want to assign it from the object inspector, and save it at runtime, then you have a copy that works.

Both different people designed that, Dibo the author of BCButton made the object inspector, and I added the functionality to load / save from file at runtime. These are not the same.

Also notice that maybe TBCButton and TBCButtonFocus behaves differently due to naming of internal components classes.

winni

  • Hero Member
  • *****
  • Posts: 3197
Re: BCButton crashes while LoadFromFile
« Reply #7 on: September 28, 2020, 11:02:48 am »
@Lainz


Hi!

File format jungle:

The file format of the delivered styles in the directory BCButton/styles is some homebrew Ini file.

The file format of TBCButton.SaveToFile is Lazarus lfm.

Is there some trick or tool to convert them: IniFile <-> lfm ????

Would be nice.

Winni

 

TinyPortal © 2005-2018