Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Help (cont'), Radio button is beging clicked by ???

Status
Not open for further replies.

rrrrr12345

Programmer
Jul 2, 2002
9
GB
Hi again, thank you for your advices, please give me comments again. Your help will be appreciated.

I have a MainForm which the user can input a number so that each set of data associated with the number is displayed using another form with radio buttons (basically):

e.g. when 'Production 1' is selected in MainForm. The content of an XML file refering to 'Production 1' would be displayed by a TRadioGroup, so, when 'Production 2' is selected, the content of 'Production 2' would be displayed, e.g.

procedure CheckStatusDisplay;
begin
StatusForm.RadioGroup.OnClick := nil;

if (P.Status = 'Accepted') then
StatusForm.RadioGroup.ItemIndex := 0;
if (P.Status = 'Rejected') ) then
StatusForm.RadioGroup.ItemIndex := 1;
// P is the appropriate Production as selected
// This was done when a different Production is selected

StatusForm.RadioGroup.OnClick := StatusForm.RadioGroupClick;
end;

Now, when the user clicks on the RadioButton, the content e.g. Accepted or Rejected, would be saved :

procedure TStatusForm.RadioButton.Click(Sender: TObject);
begin
If StatusForm.RadioButton.ItemIndex = 1 then
P.Status := 'Rejected';
If StatusForm.RadioButton.ItemIndex = 0 then
P.Status := 'Accepted';
end;


Ok, now the problem occurs when I do the following:

(i) Start the program
(ii) Select production 1

//at this point nothing would comes up as we're assuming XML is empty.

(iii) Click on Accepted

// P.Status becomes Accepted.

(iv) Select production 2

// RadioGroup becomes emty again as nothing was saved for production 2

(v) click on Status form but not in the RadioGroup, or click on maximise, etc. Not anywhere in the RadioGroup.

// now for some reason, the program runs procedure TStatusForm.RadioButton.Click(Sender: TObject); and assigned it as accepted (if I clicked rejected before, then rejected would appear)! This is strange, because I only click it at production 1 but why would the onclick event occur even I haven't click into the radiogroup? Remember that the status was re-loaded when I selected Prodcution 2, so how could this happen?

Thanks, thanks so much.
 
After processing the first pass through, reset the radio button's ItemIndex to -1. Otherwise it will retain the previous value for the next pass. This will then force the user to choose either accept or reject with each pass.
 
Thanks, I think that problem is as you said, "it will retain the previous value for the next pass", but could you explain to me what you mean by a pass? so when do I reset the radio button's ItemIndex?

 
By "pass" he refers to the next time through the event procedure. Set ItemIndex at the end of the OnClick event.

You can also speed up your code a little bit by changing the RadioButtonClick event to...

Code:
procedure TStatusForm.RadioButtonClick(Sender: TObject);
begin
  case StatusForm.RadioButton.ItemIndex of
    0: P.Status := 'Accepted';
    1: P.Status := 'Rejected';
  end; {case}
  StatusForm.RadioButton.ItemIndex:= -1;
end;

When you do case statements like this, if the possible results are listed in ascending value, the code is quicker.
 
After using that code, the RadioButton doesn't show that it's being clicked at all. I'm now trying a few things, please give some more suggestions in the mean while. Thank you so much.
 
I also forgot to say that I actually did something like this aswell:


procedure CheckStatusDisplay;
begin
StatusForm.RadioGroup.OnClick := nil;


StatusForm.RadioGroup.ItemIndex := -1;
[/red]

if (P.Status = 'Accepted') then
StatusForm.RadioGroup.ItemIndex := 0;
if (P.Status = 'Rejected') ) then
StatusForm.RadioGroup.ItemIndex := 1;
// P is the appropriate Production as selected
// This was done when a different Production is selected

StatusForm.RadioGroup.OnClick := StatusForm.RadioGroupClick;
end;
[/green]

your help will be needed, and will be appreciated
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top