Passing a parameter text to a function

Please discuss general Delphi programming topics here.

Passing a parameter text to a function

Postby Wardlow » June 2nd, 2007, 4:30 pm

I have a function that is using a parameter; text. It says that this is not permissible. Is there a way around this?


Wardlow
Wardlow
Junior Member
Junior Member
 
Posts: 38
Joined: May 31st, 2007, 10:08 pm

Postby Kambiz » June 2nd, 2007, 4:37 pm

Please post your function definition here.
Kambiz
User avatar
Kambiz
Administrator
Administrator
 
Posts: 2424
Joined: March 7th, 2003, 7:10 pm

Postby Wardlow » June 9th, 2007, 12:26 am

Code: Select all
procedure WriteFile2P(FileName: text; Name: String; Parm1: double; Parm2: double; Avg: double; count: integer);
       begin
        if count = 0 then
        begin
          AssignFile(FileName, 'c:\data.txt');
          Rewrite(FileName);
        end;

         if count = 0 then
         begin
         write(FileName, 'LengthMA1'); write(FileName, '     '); write(FileName, 'LengthMA2');
         write(FileName, '     '); writeln(FileName, 'Average PercentProfit');
         end;

         write(FileName, FileName); write(FileName, '                '); write(FileName, FileName);
         write(FileName, '                '); writeln(FileName, avg:0:2);

        end;

end.


thank you
Wardlow
Junior Member
Junior Member
 
Posts: 38
Joined: May 31st, 2007, 10:08 pm

Postby Kambiz » June 9th, 2007, 2:45 am

Text is the data type for text files.
In your function you must use String data type instead.
Kambiz
User avatar
Kambiz
Administrator
Administrator
 
Posts: 2424
Joined: March 7th, 2003, 7:10 pm

Postby Wardlow » June 9th, 2007, 4:10 am

as always, I can't thank you enough for you help
Wardlow
Junior Member
Junior Member
 
Posts: 38
Joined: May 31st, 2007, 10:08 pm

Postby Wardlow » June 14th, 2007, 7:44 pm

Kambiz,

If I define SendFile as a string, then how would I get the program to write to the File SendFile. in my main program I have already declared SendFile as a text
Wardlow
Junior Member
Junior Member
 
Posts: 38
Joined: May 31st, 2007, 10:08 pm

Postby Wardlow » June 14th, 2007, 10:38 pm

What I want to do is to clear the coding up in the main and put it into procedures and functions heres what I have in the main.

SendFile: Text;

AssignFile(SendFile, 'c:\data.txt');
Rewrite(SendFile);

writeln(Sendfile, 'Hello_World!!!');
closeFile(SendFile);


How would I declare and write a procedure to do this, so I dont' have to have the above code in the main?
Wardlow
Junior Member
Junior Member
 
Posts: 38
Joined: May 31st, 2007, 10:08 pm

Postby Kambiz » June 15th, 2007, 3:28 am

Sorry, it was my mistake. According to the parameter name, I thought you are passing name of the file. :oops:

Well, instead of the file, pass its name to the function and then declare the file variable as local in the function.
Kambiz
User avatar
Kambiz
Administrator
Administrator
 
Posts: 2424
Joined: March 7th, 2003, 7:10 pm

Postby Wardlow » June 15th, 2007, 5:47 pm

got it to work now
thank you
Wardlow
Junior Member
Junior Member
 
Posts: 38
Joined: May 31st, 2007, 10:08 pm


Return to Delphi Programming

Who is online

Users browsing this forum: No registered users and 1 guest

cron