Recent

Author Topic: [Solved] RadioGroup: Adding buttons dynamically.  (Read 3683 times)

iru

  • Sr. Member
  • ****
  • Posts: 321
[Solved] RadioGroup: Adding buttons dynamically.
« on: June 15, 2021, 05:55:31 am »
Gentlefolk,

Environment/s. Linux Mint 20.1, Laz 2.0.12 FPC 3.2.0. Win 10 Laz 2.0.10 FPC 3.2.0. Lenovo X240 I3.

At design time one adds 'strings' to RadioGroup1.Items.
In both environments the buttons and associated strings are displayed correctly.

At run time any items added dynamically by RadioGroup1.Items.Add('xxx') are NOT displayed!

I have read widely about RadioGroup in numerous forums, similar/same issues with a variety of resolutions but none make any difference.

I have tried all sorts of repaints, enable, etc, design time buttons are  displayed, none that are dynamically added.

If there is one design time item and I dynamically add two more a
vDebug := RadioGroup1.items.Count shows 2 items.

Any help, direction appreciated, Ian

« Last Edit: June 15, 2021, 02:37:10 pm by iru »

GAN

  • Sr. Member
  • ****
  • Posts: 370
Re: RadioGroup: Adding buttons dynamically.
« Reply #1 on: June 15, 2021, 08:06:08 am »
RadioGroup1.Items.Add('xxx') works fine.

Linux Mint 19.3 - Lazarus 2.0.8 and FPC 3.0.4

Code: Pascal  [Select][+][-]
  1. unit Unit1;
  2.  
  3. {$mode objfpc}{$H+}
  4.  
  5. interface
  6.  
  7. uses
  8.   Classes, SysUtils, Forms, Controls, Graphics, Dialogs, ExtCtrls, StdCtrls;
  9.  
  10. type
  11.  
  12.   { TForm1 }
  13.  
  14.   TForm1 = class(TForm)
  15.     Button1: TButton;
  16.     RadioGroup1: TRadioGroup;
  17.     procedure Button1Click(Sender: TObject);
  18.   private
  19.  
  20.   public
  21.  
  22.   end;
  23.  
  24. var
  25.   Form1: TForm1;
  26.  
  27. implementation
  28.  
  29. {$R *.lfm}
  30.  
  31. { TForm1 }
  32.  
  33. procedure TForm1.Button1Click(Sender: TObject);
  34. begin
  35.   RadioGroup1.Items.Add('test');
  36. end;
  37.  
  38. end.  
Lazarus 2.0.8 FPC 3.0.4 Linux Mint Mate 19.3
Zeos 7̶.̶2̶.̶6̶ 7.1.3a-stable - Sqlite 3.32.3 - LazReport

speter

  • Sr. Member
  • ****
  • Posts: 338
Re: RadioGroup: Adding buttons dynamically.
« Reply #2 on: June 15, 2021, 10:02:52 am »
iru, maybe you should post a simple project showing the issue you are having.

Like GAN wrote, I have not found your issue (I am using Windows though).

I am attaching my project.

cheers
S.
I climbed mighty mountains, and saw that they were actually tiny foothills. :)

iru

  • Sr. Member
  • ****
  • Posts: 321
Re: RadioGroup: Adding buttons dynamically.
« Reply #3 on: June 15, 2021, 11:30:03 am »
Gentlefolk,

Thanks for the support.

I have downloaded the sample project from speter.

It works beautifully!!!!! On the same environment as my simple project that fails.......

I will do some more research. Ian

iru

  • Sr. Member
  • ****
  • Posts: 321
Re: RadioGroup: Adding buttons dynamically.
« Reply #4 on: June 15, 2021, 02:36:15 pm »
Gentlefolk,

I installed and compiled the example supplied by speter, it works correctly!

Back into my application with the problem, installed a new RadioGroup and a RadioGroup.items.Add('something') in Form.OnShow on a complex form with a tTabControl (Radiogroup1 not on the tab).

Same problem, nothing added to the RadioGroup.Items!!

Created a new clean form in the same application, added the RadioGroup and a RadioGroup.items.Add('something') in Form.OnShow.

It works!

Back to the form which fails, there in  OnShow  back some lines before the RadioGroup1.Items.Add is a
RadioGroup1 := tRadioGroup.Create(NIL).

Delete that and the the Item.Add works OK.

I would guess that the odd RadioGroup1 := tRadioGroup.Create(NIL) in a couple of my tests would have contributed to my problems.

I need to tidy up some things.....

But why did the RadioGroup1 := tRadioGroup.Create(NIL) cause a problem? The Items.Add were after that code.

I have some work to do. Thanks for the help, Ian.

iru

  • Sr. Member
  • ****
  • Posts: 321
Re: [Solved] RadioGroup: Adding buttons dynamically.
« Reply #5 on: June 15, 2021, 03:06:34 pm »
A little more,

I have multiple RadioGroups on the form,

RadioGroup1 without a Create  works, the Item.Add adds the button.

Another radio group has a Create, remove it and I get a SigSev, on the OnShow Item.Add so therefore the .Create/s in other places.

So I have something wrong with the RadioGroup that has the SIGSEV....

Confusing, time to go to bed.... Ian.

wp

  • Hero Member
  • *****
  • Posts: 11831
Re: RadioGroup: Adding buttons dynamically.
« Reply #6 on: June 15, 2021, 03:46:55 pm »
Back to the form which fails, there in  OnShow  back some lines before the RadioGroup1.Items.Add is a
RadioGroup1 := tRadioGroup.Create(NIL).
A radiogroup within a radiogroup? Why that? Do you want to have a group of radiobuttons within a group of other radio buttons? Or what else do you want to achieve?

RadioGroup1 without a Create  works
Another mystery... Without creating a control it certainly will NOT work.

Please be more specific when posing your question. It is is very ineffectvie and disappointing when we always have to guess what the poster means...

iru

  • Sr. Member
  • ****
  • Posts: 321
Re: [Solved] RadioGroup: Adding buttons dynamically.
« Reply #7 on: June 16, 2021, 01:10:09 am »
Gentlefolk,

No there is no radiogroup in a radiogroup I was referring to a code line RadioGroupType := tradioGroup.Create in FormShow which creates the RadioGroupType (which is already defined in the form definition tFormSet = class(tObject).....

Without creating a control it certainly will NOT work. Presuming that a control defined in the form definition is automatically created in the creation of the form the RadioGroupType := tradioGroup.Create will create it twice.

Any way I added another RadioGroup to the form by drag and drop from the Standard pallete. All worked OK.

I deleted the two problem RadioGroups via the Object Editor, checked the .pas and .lfm files for any debri, cleaned out any references to these RadioGroups from my code.

Added a new RadioGroup to the TabPanel, set the same name, anchors, items, etc as one of the problem RadioGroups. Compiled clean and works OK.

Performed the same for the second dodgy RadioGroup. The new version also works OK.

No need for a  RadioGroupType := tradioGroup.Create in FormShow to avoid a SIGSEV when trying to add an item.

Looks like some ugly corruption somewhere...... Another lesson learned???

Thanks, Ian.

 

TinyPortal © 2005-2018