TOPIC: BUG: CheckBoxControl inside AccessControl
#463
BUG: CheckBoxControl inside AccessControl 3 Years, 8 Months ago
Hi, I have found a bug using a CheckBoxControl inside an AccessControl.

You can reproduce it executing the following code in the Workspace:

Code:

Window(Controller
  {
  Controls:
#(Access tables
   (Vert
(CheckBox text: "checkbox1" set: true)
(CheckBox text: "checkbox2" set: true)
   )
)
  }
)


As you can see, I have set at 'true' both the CheckBox controls in the above code, but only the first will be checked in the window that appears from its execution.

I have managed to resolve this bug modifying the Set method in CheckBoxControl code in this way:

Code:

Set(value)
{
if (value=="") return //***THIS ROW WAS ADDED BY ME
SendMessage(.Hwnd, BM.SETCHECK, value is true ? BST.CHECKED : BST.UNCHECKED, 0)
// if (Boolean?(protect = .Send('GetField', .Name $ "__protect")))
// .SetReadOnly(protect)
}



In this way I think I have resolved my problem, but I don't know if it's the right way to do it.
 
 
Mauro
 
#464
Re:BUG: CheckBoxControl inside AccessControl 3 Years, 8 Months ago
Hello,

There are a few controls that support a "set" option. This option was never intended to work inside a RecordControl (AccessControl uses RecordControl). In a RecordControl, the value of the control is supposed to correspond to the data record's field value.

There are a couple of options, you could move the checkboxes outside the AccessControl, or if you just wanted defaults for the fields, you could use rules to default the values.

Post edited by: jferguson, at: 2006/12/05 15:42
 
 
Jeff Ferguson
Suneido Software
 
#466
Re:BUG: CheckBoxControl inside AccessControl 3 Years, 8 Months ago
Hi, moving the checkbox outside the AccessControl it is not an option for me, because the checkbox has to be near some fields inside the AccessControl. Anyway I would like to know if my mod in the Set method could give me problems.
 
 
Mauro
 
#469
Re:BUG: CheckBoxControl inside AccessControl 3 Years, 8 Months ago
I don't think your changes should cause you problems. A better solution, in my opinion, would be to add names to the checkboxes and then define rules for them to default them to checked. For example:

Code:


Window(Controller
  {
  Controls:
    #(Access tables
       (Vert
        (CheckBox text: "checkbox1" name: 'test_checkbox1')
        (CheckBox text: "checkbox2" name: 'test_checkbox2')
       )
    )
  }
)


Rule_test_checkbox1
function ()
    {
    return true
    }

Rule_test_checkbox2
function ()
    {
    return true
    }




 
 
Jeff Ferguson
Suneido Software
 
#470
Re:BUG: CheckBoxControl inside AccessControl 3 Years, 8 Months ago
Hi, thank you for your solution... Anyway I have found that if I give a name to a checkbox control, then its set option is not working anymore. For exemple, in the following code:
Code:

Window(Controller
  {
  Controls:
      #(Access prova
(Vert
  (CheckBox name: "c1" text: "checkbox1" set: true)
  (CheckBox name: "c2" text: "checkbox2" set: true)
  (CheckBox text: "checkbox3" set: true)
)
      )
  }
)

If I don't define a Rule for 'c1' and 'c2', then the set option of checkbox is not working. I don't think this is the right behaviour, because if there isn't a related Rule, then the set option should be working. However, with my little mod to the Set(value) method in CheckBoxControl code, the above code is working as expected.


P.S.: I know that from your point of view it's better to not modify the code in stdlib, but I think that if in the stdlib there is a bug, it is better to solve it in the stdlib, even if there were one or two alternatives to getting around the problem. A bug is a bug and I think it is always bad to leave it there... ;)
 
 
Mauro
 
#474
Re:BUG: CheckBoxControl inside AccessControl 3 Years, 8 Months ago
I'm sorry, there must be a misunderstanding.

The "set" option for controls will not work inside a RecordControl (or AccessControl because Access uses a RecordControl). In a RecordControl, all data controls' values are set from the Record, regardless of any option used by the control. The "set" option was never intended to be used in a RecordControl.

If you want your control to have a default value when inside a RecordControl, you should use a rule. You should not use the "set" option if you are using a rule, they do not work in combination.

In my opinion, this is not a bug.
 
 
Jeff Ferguson
Suneido Software
 
#477
Re:BUG: CheckBoxControl inside AccessControl 3 Years, 8 Months ago
I understand that from the point of view of the RecordControl developer, that behaviour could be considered normal. But to me, a generic Suneido user that doesn't know (and possibly wouldn't want to know :P) the inner details of RecordControl implementation, this behaviour appears really as a bug.
On the other hand, if one wanted to prevent using of 'set' option inside a control defined in a RecordControl, I think that the right thing to do would be to inform the user with a run-time error as:
"Error: 'set' option inside RecordControl is not allowed. Suggestion: use a Rule instead.".
Another option could be to allow using of set option inside a RecordControl (as appears to do my little mod to the Set(value) method).
One of two above option is ok for me, but to allow a strange behaviour (for an user, not for a Suneido developer..) I think is not right. ;)
 
 
Mauro
 
#478
Re:BUG: CheckBoxControl inside AccessControl 3 Years, 8 Months ago
jferguson wrote:
[...]You should not use the "set" option if you are using a rule, they do not work in combination.[...]But in my last example I have used the 'set' option without defining any rule...
 
 
Mauro
 
#479
Re:BUG: CheckBoxControl inside AccessControl 3 Years, 8 Months ago
I agree, we should probably either handle the set option in RecordControl, or make it more clear to the Suneido user that it will not work, possibly with an exception as you have suggested.

One idea I had was to not register the control with RecordControl if the set option was used on the control. That way the RecordControl will ignore that control and then the application code becomes responsible for getting and setting the value in that control (and the set option will work then). Not sure yet if this is a good idea or not.
 
 
Jeff Ferguson
Suneido Software
 
#483
Re:BUG: CheckBoxControl inside AccessControl 3 Years, 8 Months ago
One problem with your fix is that if the database has "" in some records, then the Set will not work and whatever previous value was in there would stay.

At first, I did not understand why your very first example did not work. Since you were not giving names, RecordControl should not interfere. Then I realized that controls have default names (in this case "CheckBox"). I thought maybe we could specify name: "" or name: false, but RecordControl does not handle this.

So another "fix" would be to modify RecordControl to ignore any controls whose name is false. The problem is that this would make it difficult to refer to these controls from your code.

My next thought was to "fix" the CheckBox set option to work with RecordControl. But when I look at the code, it looks like we tried to do this - by sending NewValue (which is normally for RecordControl)

So we do not want to throw an exception if you use the set option inside a RecordControl because it will actually work (in some situations)

The problem is that when you use a RecordControl, the first thing you usually do is Set the data for it. (e.g. AccessControl initially displays the first/last record or a new record if none exist) This means that any value that was supplied by a control's set argument is lost.

Another "fix", would be to have an option to controls to specify that it should not be handled by RecordControl (i.e. should not send the Data registration)

My question is - what are you trying to do? Do you want the checkboxes set once when the Access starts? Or every time you change records in the Access? Or only new/old records? Do these checkboxes have fields in the database or not? It is unlikely that any "fix" will handle all these situations.
 
 
andrew
 
#487
Re:BUG: CheckBoxControl inside AccessControl 3 Years, 8 Months ago
andrew wrote:
One problem with your fix is that if the database has "" in some records, then the Set will not work and whatever previous value was in there would stay.[...]Hi, how it is possible that some database field related to a checkbox control have a "" in the field? The Set(value) method in the CheckBoxControl can set only a true or false boolean value. The problem could arise if I use a CheckBox control on a field that could contain a not boolean value, but this would be a logic inconsistence, probably related to manual operations on the tables. But, in an application the operations have to be done by the app itself, not by hand in the Query Window (that it should be only for 'service ops' and Suneido learning).
Anyway, if for some strange reason there were a "" in a field that it is supposed to contain true or false, I think that a return from Set(value) method in CheckBoxControl doesn't break anything...
[...]My question is - what are you trying to do? Do you want the checkboxes set once when the Access starts? Or every time you change records in the Access? Or only new/old records? Do these checkboxes have fields in the database or not? It is unlikely that any "fix" will handle all these situations.
The checkboxes I use in the AccessControl are not related to a database field. They are needed to trigger some events (the click on the checkbox is intercepted in the Access_RecordChange method) that consist in the automatic set of another checkbox and, in case, some other things.
These checkboxes have to be set in a predefined way only when the Access starts. For the next records the checkboxes have to remain in the previous status.

I have tried another solution:

Code:

Window(Controller
  {
  New()
{
.Access.GetControl("c1").Set(true)
.Access.GetControl("c2").Set(true)
}
  Controls:
    #(Access tables
       (Vert
        (CheckBox name: "c1" text: "checkbox1")
        (CheckBox name: "c2" text: "checkbox2")
       )
    )
  }
)

I have set at true the checkboxes inside the New() method. At first, it appears to work, but if you click on the 'Edit' or 'New' button, the checkboxes will be set at false. Instead, with my fix, above code is working well as expected.

Post edited by: Mauro, at: 2006/12/12 16:03
 
 
Mauro
 
#489
Re:BUG: CheckBoxControl inside AccessControl 3 Years, 8 Months ago
It may not "make sense" but "" can end up in the data for various reasons. Your fix would cause problems because when you clicked on Next/Previous/New in Access because a Set("") would be ignored and the control would visually display whatever value it contained from the previous record.

For your case I would say the best "fix" would be to add an option to the control to specify that it should NOT be controlled by RecordControl. (i.e. not Send the Data registration)
 
 
andrew
 
#490
Re:BUG: CheckBoxControl inside AccessControl 3 Years, 8 Months ago
andrew wrote:
It may not "make sense" but "" can end up in the data for various reasons. Your fix would cause problems because when you clicked on Next/Previous/New in Access because a Set("") would be ignored and the control would visually display whatever value it contained from the previous record.[...]

From a conceptual point of view I think it is right that a Set("") on a CheckBox control doesn't do anything. After all, a checkbox value should be true or false, so passing a "" value how should be interpreted by Suneido?
The problem here is that RecordControl passes "" when it has to 'reset' a field, for example, in case of clicking on New button. This is suitable for a Field control, but what for a CheckBox control? It should reset the checkbox status to a default value... But what is the default value for a CheckBox control? Of course, using a Rule I can define a default value, but if there weren't any Rule, what should the right behaviour be? In this case, I think the default value should be false, unless that I have used the set option in the control. In this last case, the default value should be that given in the 'set' option.

Therefore we would want to have:

Set("") & (CheckBox set: true) => set default value: true
Set("") & (CheckBox set: false) => set default value: false
Set("") & (CheckBox) - without defining set - => set default value: false

Obviously, Rules and stickyFields option should work as expected.

I have managed to do this by the following little mods in the CheckBoxControl code (I have modded New and Set methods):

Code:

set: false //***ADDED BY ME (default value of checkbox)
New(text = "", lefttext = false, font = "", size = "", weight = "",
readonly = false, set = "", tip = "")
{
text = TranslateLanguage(text)
.CreateWindow("button", text,
WS.VISIBLE | WS.TABSTOP | BS.AUTOCHECKBOX | (lefttext ? BS.LEFTTEXT : 0))
d = 12 // how to determine the dimensions of a checkbox?
.SetFont(font, size, weight, text is '' ? 'M' : text)
if (text is "")
.Xmin = d
else
.Xmin += (.Ymin / 4).Int() + d + 2 // text is indented !
.Ymin = Max(d, (++.Ymin/2).Int() * 2 + 6) // ensure nicely centered
.Top += 3
.Left = lefttext ? .Xmin - 12 : .Left
.Send("Data")
.Map = Object()
.Map[BN.CLICKED] = 'BN_CLICKED'
.SetReadOnly(readonly)
.readonly = readonly
//***ADDED BY ME:
if set is true
.set = true
//***************
if (set isnt "")
{
.Set(set)
.Send("NewValue", .Get())
}
if tip isnt ''
.ToolTip(tip)
}
...
...
Set(value)
{
//****ADDED BY ME TO MANAGE THE "" CASE:
if value is ""
value = .set
//**************************************
SendMessage(.Hwnd, BM.SETCHECK, value is true ? BST.CHECKED : BST.UNCHECKED, 0)
// if (Boolean?(protect = .Send('GetField', .Name $ "__protect")))
// .SetReadOnly(protect)
}



Post edited by: Mauro, at: 2007/02/01 15:58
 
 
Mauro
 
#503
Re:BUG: CheckBoxControl inside AccessControl 3 Years, 8 Months ago
Hi, what do you think of the mods in the above post? I think they resolve all the pointed out problems and they shouldn't brake anything from preexisting Suneido applications that use CheckBoxControl.
 
 
Mauro
 
#519
Re:BUG: CheckBoxControl inside AccessControl 3 Years, 7 Months ago
Sorry, I have been away over the holidays, I will look at your changes.
 
 
andrew