Lazarus file I/O skeleton

Pretty much got this file I/O GUI skeleton the way I want. There’s a place to enter both input and output files. Then proceed to a input/output loop where I can read an output file preform various operations then write output. This is the basis of many things I do. It took my longer to write this than I wish it did. But then again I am a Lazarus and Pascal newbe…in a way. For example the following code gave me problems

 // Check to see if Output file exists!
 gotOutput:=False;
  if FileExists(ofil) then
     begin
          resp:=InputBox('Error', 'File exists! Keep (Y) or N?', 'Y');
          if UpperCase(resp) = 'Y' then
             begin
                  ShowMessage('Keeping!');
                  OutFilename.FileName:='xxx' // Why isn't this overwriting
             end
          else
            //ShowMessage('Overwriting!');
            gotOutput:=True;
     end
  else
     gotOutput:=True;

This code was in my file output onChange event. If the user chooses to keep an existing file…the ‘Keeping!’ message would display however the very next statement with my comment “Why isn’t this overwriting” wasn’t. I wanted to clear the field and only put the ‘xxx’ there for more assurance that something was happening. However it did cause the onChange event to trigger itself, causing an endless loop. I added a Clear Output button and moved the clearing code there and it worked. So since it worked after the onChange event completed, I put the clear code in the onExit event…and it worked!

procedure TForm1.OutFilenameExit(Sender: TObject);
begin
if not(gotOutput) then
begin
OutFilename.FileName:='';
OutFilename.Text:='Enter Output Filename';
end;
end;