View Issue Details

IDProjectCategoryView StatusLast Update
0027042LazarusLCLpublic2015-05-09 14:23
ReporterReinhard BergerAssigned ToBart Broersma 
PrioritynormalSeverityminorReproducibilityalways
Status closedResolutionfixed 
PlatformQt,Win32,GTK2OSLinuxOS Version
Product Version1.2.3 (SVN)Product Build 
Target Version1.2.8Fixed in Version1.2.8 
Summary0027042: Property "RadioGroup.Controls[x] not in sync with RadioGroup.items[x]
DescriptionIn Lazarus 1.1 the 2 properties
"RadioGroup.items" and "RadioGroup.controls" was in sync
means value [1] from items was the same as value [1] from controls.

Since V1.3 this 2 properties are out of sync.

Eg.

Poperty items : [0]=item#0
                [1]=item#1
                [2]=item#2
                [3]=item#3


Property : controls.caption
                [0]=item#0
                [1]=HiddenRadioButton
                [2]=[1]=item#1
                [3]=[2]=item#2

The item 0000003 with name "item#3" is also not there (cut off) since the "Hidden Radio" is inserted before.

Also shomehow in debug mode a empty line will be inserted before item#0 (see attached photo)






Steps To ReproduceCreate a value of Tradiogroups and name it.

Additional InformationAs seen on picture on lazarus 1.1 all was in sync.

1st left window shows laz 1.1 (win32) (Release)
2nd window to right shows laz 1.3 (win32) (Release)
3nd window to right shows laz 1.3 qt (linux) (Release)
4th window to right shows laz 1.3 qt (Linux) (Debug)

TagsNo tags attached.
Fixed in Revisionr46964
LazTarget-
WidgetsetGTK 2, Win32/Win64, QT
Attached Files
  • tradio.jpg (89,319 bytes)
    tradio.jpg (89,319 bytes)
  • TRadioBug.zip (391,627 bytes)
  • radiogroup.diff (598 bytes)
    Index: lcl/include/radiogroup.inc
    ===================================================================
    --- lcl/include/radiogroup.inc	(revision 46786)
    +++ lcl/include/radiogroup.inc	(working copy)
    @@ -232,6 +232,9 @@
             ARadioButton.Checked := (i = FItemIndex);
             ARadioButton.Visible := true;
           end;
    +      //FHiddenButton must remain the last item in Controls[], so that Controls[] is in sync with Items[]
    +      Self.RemoveControl(FHiddenButton);
    +      Self.InsertControl(FHiddenButton);
           FHiddenButton.Checked := (FItemIndex = -1);
           UpdateTabStops;
         end;
    
    radiogroup.diff (598 bytes)

Activities

Reinhard Berger

2014-11-14 13:16

reporter  

tradio.jpg (89,319 bytes)
tradio.jpg (89,319 bytes)

Reinhard Berger

2014-11-14 13:16

reporter  

TRadioBug.zip (391,627 bytes)

Juha Manninen

2014-11-14 13:39

developer   ~0079146

Last edited: 2014-11-14 15:27

View 2 revisions

Can you find a revision that broke it?

> Since V1.3 this 2 properties are out of sync.

Your Product Version says 1.2.3. So, the error is already in 1.2.x series, not only in 1.3 trunk?

Zeljan Rikalo

2014-11-14 16:12

developer   ~0079147

This is ugly bug, it must be fixed asap.

Bart Broersma

2014-11-14 17:09

developer   ~0079149

Posible candidates: r41551, and related 42772, 42774, 43223 ?

Zeljan Rikalo

2014-11-14 17:35

developer   ~0079150

I don't see any problem with r41551, it doesn't have anything to do with items, but others ....well Bart, you have to dig in ;)

Bart Broersma

2014-11-14 18:09

developer   ~0079151

Last edited: 2014-11-14 18:11

View 2 revisions

Sorry, I meant r42772, and related 42774, 43223 (not r41551)

Bart Broersma

2014-11-14 18:52

developer   ~0079152

Looking at the pictures, I see that 1.1 did not have the HiddenRadioButton, so this will make ControlCount always be Items.Count + 1

Bart Broersma

2014-11-14 19:49

developer  

radiogroup.diff (598 bytes)
Index: lcl/include/radiogroup.inc
===================================================================
--- lcl/include/radiogroup.inc	(revision 46786)
+++ lcl/include/radiogroup.inc	(working copy)
@@ -232,6 +232,9 @@
         ARadioButton.Checked := (i = FItemIndex);
         ARadioButton.Visible := true;
       end;
+      //FHiddenButton must remain the last item in Controls[], so that Controls[] is in sync with Items[]
+      Self.RemoveControl(FHiddenButton);
+      Self.InsertControl(FHiddenButton);
       FHiddenButton.Checked := (FItemIndex = -1);
       UpdateTabStops;
     end;
radiogroup.diff (598 bytes)

Bart Broersma

2014-11-14 19:50

developer   ~0079153

Setting the parent of FHiddenButton causes the out-of-sync issue.
Possible fix (but rather ugly hack) attached.

Reinhard Berger

2014-11-14 22:38

reporter   ~0079155

r41582 (V1.1) doesn't show this.
next Version i have is r45510 (1.2) there this bug appears for me the first time until now.

Bart Broersma

2014-11-15 18:32

developer   ~0079165

Setting FHiddenButton.Parent := Self already exists since r5951 (in the year 2004).
It's unclear to me why it did not end up in TRadioGroup.Controls[] before...

Bart Broersma

2014-11-15 18:51

developer   ~0079166

Last edited: 2014-11-15 18:57

View 2 revisions

> This is ugly bug, it must be fixed asap
Apart from it being a little odd, what exactly is the problem with it?
Does any code rely on Controls[x] <=> Items[x]?

If you need to access the radiobuttons and need to have them in sync you could use Components[] instead.

Reinhard Berger

2014-11-15 21:33

reporter   ~0079167

It is the index of the controls which is then out of sync.

By using this example :

If you use lazarus 1.1 and use "Radiogroup1.Controls[1].Enabled:=false"
it will set the correct 1st (called : item#1) to disable.

If you use laz 1.2/1.3 and set "Radiogroup1.Controls[1].Enabled:=false"
it will not work, since it sets the hidden radiobutton to disable and not the visible (correct) one.

If you want to disable under laz 1.2/1.3 the "item#1" you need to inc the index from 1 to 2.

Means "Radiogroup1.Controls[2].Enabled:=false" will work.

Ok not a big problem when you know it, but i'm sure not all people know that since they count the visible "items" in design mode and later in code trying to set index[1] does not work.

ALso if you compile your prog with different version of lazarus the result is different then.

Don't know what happens when you use a delphi code and compile it.

Output should be the same an all versions without need to modify the source code all the time.

Bart Broersma

2014-11-15 22:31

developer   ~0079168

> Means "Radiogroup1.Controls[2].Enabled:=false" will work.

Well, valid argument.

Does Delphi guarantee that this works (as in:is it by design) or does it happen to work (just because it's a side effect of the actual implementation)?

We can fix it (sort of), see my patch, but ControlCount will always be > Items.Count (at least from the moment on that an item was added to the list), which is not compatible with Delphi's implementation...

Issue History

Date Modified Username Field Change
2014-11-14 13:16 Reinhard Berger New Issue
2014-11-14 13:16 Reinhard Berger File Added: tradio.jpg
2014-11-14 13:16 Reinhard Berger File Added: TRadioBug.zip
2014-11-14 13:39 Juha Manninen Note Added: 0079146
2014-11-14 15:27 Juha Manninen Note Edited: 0079146 View Revisions
2014-11-14 16:12 Zeljan Rikalo Note Added: 0079147
2014-11-14 17:09 Bart Broersma Note Added: 0079149
2014-11-14 17:35 Zeljan Rikalo Note Added: 0079150
2014-11-14 18:09 Bart Broersma Note Added: 0079151
2014-11-14 18:11 Bart Broersma Note Edited: 0079151 View Revisions
2014-11-14 18:52 Bart Broersma Note Added: 0079152
2014-11-14 19:49 Bart Broersma File Added: radiogroup.diff
2014-11-14 19:50 Bart Broersma Note Added: 0079153
2014-11-14 22:38 Reinhard Berger Note Added: 0079155
2014-11-15 18:32 Bart Broersma Note Added: 0079165
2014-11-15 18:51 Bart Broersma Note Added: 0079166
2014-11-15 18:57 Bart Broersma Note Edited: 0079166 View Revisions
2014-11-15 21:33 Reinhard Berger Note Added: 0079167
2014-11-15 22:31 Bart Broersma Note Added: 0079168
2014-11-19 20:08 Bart Broersma Assigned To => Bart Broersma
2014-11-19 20:08 Bart Broersma Status new => assigned
2014-11-22 15:48 Bart Broersma Fixed in Revision => r46964
2014-11-22 15:48 Bart Broersma LazTarget => -
2014-11-22 15:48 Bart Broersma Status assigned => resolved
2014-11-22 15:48 Bart Broersma Fixed in Version => 1.2.8
2014-11-22 15:48 Bart Broersma Resolution open => fixed
2014-11-22 15:48 Bart Broersma Target Version => 1.2.8
2015-05-09 14:23 Bart Broersma Status resolved => closed