Board index » delphi » Groupbox RadioButtons

Groupbox RadioButtons

I have a form ( D1 ) with a TGroupBox which contains two TRadioButtons.
When I open a file (data file used by app) a value is read from the file
and the appropriate TRadioButton is checked ie; { Button.checked := (value
= x); } This works fine until I check one of the TRadioButtons manually,
from then on when a new file is opened the 'checked' button does not
change, whichever one was checked stays checked. Any ideas/help would be
appreciated.

Thanks
Chris
c8...@aol.com

 

Re:Groupbox RadioButtons


Quote
C8591 wrote:

> I have a form ( D1 ) with a TGroupBox which contains two TRadioButtons.
> When I open a file (data file used by app) a value is read from the file
> and the appropriate TRadioButton is checked ie; { Button.checked := (value
> = x); } This works fine until I check one of the TRadioButtons manually,
> from then on when a new file is opened the 'checked' button does not
> change, whichever one was checked stays checked. Any ideas/help would be
> appreciated.

> Thanks
> Chris
> c8...@aol.com

send a sample of exactly what you are doing.

Re:Groupbox RadioButtons


Quote
> I have a form ( D1 ) with a TGroupBox which contains two TRadioButtons.
> When I open a file (data file used by app) a value is read from the file
> and the appropriate TRadioButton is checked ie; { Button.checked :=
(value
> = x); } This works fine until I check one of the TRadioButtons manually,
> from then on when a new file is opened the 'checked' button does not
> change, whichever one was checked stays checked. Any ideas/help would be
> appreciated.

> Thanks
> Chris
> c8...@aol.com
>>send a sample of exactly what you are doing.

Here goes...

When app is created:
   gets the last file opened and reads data (useing LoadTheFile)
   checks/unchecks either the Paid or UnPaid RadioButton (in a TGroupbox)
   sets the form caption (useing SetFormCaption)

When diff. files are opened:
   file is selected (TForm3.Okay_BtnClick)
   reads data (useing LoadTheFile)
   checks/unchecks either the Paid or UnPaid RadioButton (in a TGroupbox)
   sets the form caption (useing SetFormCaption)

Everthing works fine opening and closeing files ie;
  1]  (file is unpaid)  NotPaid_RBtn is checked and caption is '...Unpaid'
  2]  (file is paid)    Paid_RBtn is checked and caption is '...Paid'
  3]  (file is unpaid)  NotPaid_RBtn is checked and caption is '...Unpaid'
  4]  (file is paid)    Paid_RBtn is checked and caption is '...Paid'

Problem occurrs when RadioButton is checked using mouse/keyboard ie;
  1]  (file is unpaid)  NotPaid_RBtn is checked and caption is '...Unpaid'
     ***Paid_RBtn is checked by user***
                        Paid_RBtn is checked and caption is '...Paid'

  2]  (file is paid)    Paid_RBtn is checked and caption is '...Paid'
  3]  (file is unpaid)  Paid_RBtn is checked and caption is '...Paid'
  4]  (file is paid)    Paid_RBtn is checked and caption is '...Paid'

             also

  1]  (file is unpaid)  NotPaid_RBtn is checked and caption is '...Unpaid'
     ***UnPaid_RBtn is checked by user (note: already was checked) ***
                        NotPaid_RBtn is checked and caption is '...Unpaid'

  2]  (file is paid)    NotPaid_RBtn is checked and caption is '...Unpaid'
  3]  (file is unpaid)  NotPaid_RBtn is checked and caption is '...Unpaid'
  4]  (file is paid)    NotPaid_RBtn is checked and caption is '...Unpaid'

  Each time a file which should change the RadioButton is opened can see
the correct button get checked and then immediatlly change back to prev.
button.
  Have tried calling the Click event instead of xxx.checked := xxx, also
tried using BM_SETCHECK (got very strange results with it).
  It almost seems like changeing the value of the checked property does
not notify the Groupbox that the selected button has changed and is
changeing it back to whatever it was prev.

-------------snipped from app------------------------------------------

procedure TForm3.Okay_BtnClick(Sender: TObject);
begin
  LoadTheFile(VF_Path + FileList_Grid.Cells[5, FileList_Grid.Row]);
  SetTimeDates(Form1.WE_MaskEdit.Text);
  Close;
end;

procedure LoadTheFile(F_Name : string);
var
  ATextFile : TextFile;
  CharArray : TCharArray;
  Str : string;
  I, J : Integer;

begin
        {other data is read here..}

        ReadLn(ATextFile, Str);
        {Form1.NotPaid_RBtn.Checked := (Str = 'NotPaid');
        Form1.Paid_RBtn.Checked := (Str = 'Paid');}      {tried this way}
        Form1.NotPaid_RBtn.Checked := (Str = 'NotPaid');
        Form1.Paid_RBtn.Checked := not(Form1.NotPaid_RBtn.Checked);

        {other data is read here..}
end;

procedure TForm1.Paid_RBtnClick(Sender: TObject);
begin
  SetFormCaption;
end;

procedure TForm1.NotPaid_RBtnClick(Sender: TObject);
begin
  SetFormCaption;
end;

procedure SetFormCaption;
var
  S : string;
begin
  if not Form1Modified then Form1Modified := true;
  with Form1 do
  begin
    if (NotPaid_RBtn.Checked) then
      S := '   ( Unpaid )'
    else S := '   ( Paid )';
    {maxlength of CustName_ComBox is 40}
    Caption := JobNum_Edit.Text + ' - ' + CustName_ComBox.Text +
               ' - ' + WE_MaskEdit.Text + S;
  end; {with}
end;

-------------------------------------------------------------------

Chris
c8...@aol.com

Re:Groupbox RadioButtons


  Found the fix for it, had to disable the RadioButtons then set the
checked property and then enable them again. Think it was related somehow
to using a modal form to open and load the files.
  Strange thing is that out of all the controls (editboxes, stringgrids,
comboboxes...) whose values/propertys were changed by loading the files
the only ones that didn't work right were the TRadioButtons???

Chris
c8...@aol.com

Other Threads