Re: File I/O problems?

[ Delphi Forum ] [ Delphi Tutorials -- by DelphiLand ]

Posted by webmaster Guido on June 26, 2003 at 15:16:04:

In Reply to: File I/O problems? posted by El+p12333 on June 25, 2003 at 03:15:48:

: Hi,
: I have a simple application that has a bunch of GroupBoxes and Checkboxes within the GroupBoxes. The way it is supposed to work is if a checkbox within a groupbox is checked then print to a file something. I have the code below. Please help. Thanks

: [for entire code: see previous message]

: procedure TFormRangeSelectorTest.NFETRangeClick(Sender: TObject);
: var
: NFile:TextFile;
: begin
:   AssignFile(NFile,'C:\Proj\Delphi\delphi6\RangeSelTest\Run0.cir');
:   Rewrite(NFile);
:   if CheckBoxTypicalN.Checked then begin
:     writeln(Nfile,'.PARAM Ncorner=0');
:     LabelNfetValue.Caption:=IntToStr(0);
:   end;
:   CloseFile(NFile);
: end;


I assume that your problem is as follows: something is written to file if the groupbox itself is clicked (a click on an open spot in the groupbox), but not when a checkbox is clicked.

Solution: write an onclick event handler for the checkboxes, not for the groupboxes.

So the first thing to do: create an onclick event handler for a checkbox, say for CheckBoxTypicalN, and copy the code from procedure TFormRangeSelectorTest.NFETRangeClick to it:

procedure TFormRangeSelectorTest.CheckBoxTypicalNClick(Sender: TObject);
  // and so on...

Next, assign that same event handler to all the checkboxes of the same group. Do this as follows:
- select a checkbox;
- in the Object Inspector, open the dropdown list next the OnClick event and select CheckBoxTypicalNClick;
- repeat for all the checkboxes of the group.

Next, expand the code in CheckBoxTypicalNClick with some "if" instructions, so that a different thing is written for each checkbox that was clicked:

if CheckBoxTypicalN.Checked then begin
  ...code for CheckBoxTypicalN
else if CheckBoxFastN.Checked then begin
  ...code for CheckBoxTypicalN
else if... and so on...

Finally, delete the OnClick handlers of the groupboxes.

[ Delphi Forum ]
[ DelphiLand: free Delphi source code, tips, tutorials ]