Procedure help

I need help I have 2 procedures ( 1 and 2 ) it is normal Delphi procedures now I assign a file in procedure 1 and I read from it and assign it to FileStr but I dont close the file with CloseFile (DataFile) now in my procedure 2 I want to use same of the data from procedure 1 like FileStr and then I will close the file in procedure 2 with CloseFile (DataFile)

Comments

: Hi all: : I need help : I have 2 procedures ( 1 and 2 ) it is normal Delphi procedures now I assign a file in procedure 1 and I read from it and assign it to FileStr but I dont close the file with CloseFile (DataFile) : now in my procedure 2 I want to use same of the data from procedure 1 like FileStr and then I will close the file in procedure 2 with CloseFile (DataFile) : : Now how do I share data between procedures? : : : [code]: {===================================================}: var: DataFile : TextFile;: FileStr : string;: {===================================================}: : procedure TfrmQues2.btnDisplayFileClick(Sender: TObject);: : begin: AssignFile(Datafile,edtFileName.Text);: reset(DataFile);: while not eof(DataFile) do: begin: readln(DataFile,FileStr);: redOutput.Lines.Add(FileStr);: : end;: end;: {===================================================}: : procedure TfrmQues2.btnDisplayPictureClick(Sender: TObject);: var: Position,LengthLine : integer;: CodeLine :string;: Found : Boolean;: : begin: Found := False;: : : LengthLine := length(FileStr);: Position := pos(edtCode.Text,FileStr);: : if ( Position > 0 ) then: begin: Found := True;: CodeLine := copy(FileStr,1,LengthLine);: form1.redOutput2.lines.Add(CodeLine);: : delete(CodeLine,Position,length(edtCode.Text));: form1.RichEdit1.Lines.add(CodeLine);: : end;: end;: : IF ( Found = False ) THEN: ShowMessage('The code '+ frmQues2.edtCode.Text +' wasn''t'+' found');: : end;: : [/code]: You can share data by either using global variables or object fields. Given that both are methods of the same form, object fields are preferred, since their scope is less than the global variables.