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 Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Procedure Textfile Type Parameter Not Allowed

Status
Not open for further replies.

6volt

Programmer
Jun 4, 2003
74
US
It appears you can't pass a TextFile as a Parameter in a Procedure:

PROCEDURE WORKonDATA (dataFile : TextFile; dataFileName : String )

This probably has something to do with the fact that the dataFile is a Pointer or something. (I am a Just Beginner... UGH!)

Does anyone know how to pass dataFile as a Parameter?

Thanks in advance
Tom

PS. I could make it Global but I want to have a general purpose Proc.
 
You could instead pass in the filename and assign it to a local TextFile variable:
Code:
procedure WorkOnData(ADataFilename: String);
var
  myFile : TextFile;
begin
  AssignFile(myFile, ADataFilename);
  ...
end;

Clive [infinity]
Ex nihilo, nihil fit (Out of nothing, nothing comes)
 
Thanks Stretch

Basically, I started with what you proposed until I had to use a process which is general purpose and warrants a Procedure for future incorporations.

So within your BEGIN...END, I want to put my PROCEDURE where I must pass the file handle. (I just learned that TextFile type is a handle - and that is probably the problem.)
 
No, I still need to pass the Textfile type in my general purpose procedure which works on an already opened and assigned file.

I'm looking into passing a Pointer to the Textfile....
 
Yes, but not in the way you think.

The compiler is quite correctly prohibiting your PROCEDURE WORKonDATA (dataFile : TextFile; dataFileName : String ) line.

Note that it's not either var or const--which means a local copy is being made. Only copies don't exactly work as expected with files, changes made to one copy may affect another. Thus the compiler stops you from making such implicit copies. The solution is simple:

Procedure WorkOnData(var DataFile : TextFile; DataFileName : String);
 
Consider using a TFileStream instead of a text file. You can pass it as a parameter and you can do bvasically anything you can do with a file handle.

Cheers
 
hi

I also had this problem and I did the 'bad' thing of making the textfile variable global - works a treat, though [smile2]

lou

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top