Solved

text files for I/O

Posted on 1998-03-11
6
131 Views
Last Modified: 2010-04-06
{I'm just started learning Delphi this week }
I need a program to write real numbers and string text to a textfile and read them out to a 2 dimensional array and preform some calculations and output onto the form.

If you could help me out with answers or sample code that'd be great.
0
Comment
Question by:roadie031198
6 Comments
 

Author Comment

by:roadie031198
ID: 1360409
Edited text of question
0
 

Expert Comment

by:Marcelito
ID: 1360410
You need create a variable like this

var VariableName:Text;
     buffer:string;

Then you can try open the file:

   AssignFile(VariableName,"PhysicalName of file (on disk)"); { Map variable to a real file}
   Rewrite(LogFile); {Clear and open the file}

If you want write
 
   Write(VariableName,"text that you want write")

or

  Writeln(VariableName,"text that you want write")

If you want read from file

  Readln(VariableName,buffer) {Read one line from the file and set to next line}

When you finish
 
  CloseFile(VariableName).

If you have doubts, write again. GoodLuck!!!!!!




0
 
LVL 8

Expert Comment

by:ZifNab
ID: 1360411
Yo roadie,

That VariableName can be everything.

eg. You want to write strings (chars) to a file :
           VariableName : File of char
                                  or  File of String
                                  or  Text  (Short for File of String)
     You want to write numbers ? :
           VariableName : File of integer
                                  File of real;
     You want to write records ? :
          Score = RECORD
            Name : string[50];
            Value : Real;
          End;
           
                  --> VariableName : Score

......... and keep going on, on, on, on ...............

Regards, Zif.

Nice to hear about newcommers.

Succes!
     
0
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 3

Accepted Solution

by:
williams2 earned 50 total points
ID: 1360412
Why don't people keep it simple to beginners, I wouldn't understand a bit of it (No offence), here's some sample code:

Procedure WriteToFile(FileName,Text: String);
var
  F: File of text; //Pascal Style
  //F: Textfile; //Delphi style
Begin
  Try
    AssignFile(F,Filname);
    FileMode:= fmOpenReadWrite; //See Delphi help File-mode constants.
    Reset(F);
    WriteLn(F,Text);
    //Write(F,Text);
    //Write(F,Text,' Hello World ');
  Finally
    CloseFile(F);
  End;
End;  
 
0
 

Author Comment

by:roadie031198
ID: 1360413
thanks alot

sorry for the late reply
0
 
LVL 3

Expert Comment

by:williams2
ID: 1360414
Don't mention it. If you have found it usefull, that's satisfaction enough to me. The others somehow did come up with different and correct answers, but it happens too often that experts don't seem to come up with simple answers, and that's a hint to everyone. Keep it simple!
0

Featured Post

Secure Your Active Directory - April 20, 2017

Active Directory plays a critical role in your company’s IT infrastructure and keeping it secure in today’s hacker-infested world is a must.
Microsoft published 300+ pages of guidance, but who has the time, money, and resources to implement? Register now to find an easier way.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Objective: - This article will help user in how to convert their numeric value become words. How to use 1. You can copy this code in your Unit as function 2. than you can perform your function by type this code The Code   (CODE) The Im…
In my programming career I have only very rarely run into situations where operator overloading would be of any use in my work.  Normally those situations involved math with either overly large numbers (hundreds of thousands of digits or accuracy re…
Email security requires an ever evolving service that stays up to date with counter-evolving threats. The Email Laundry perform Research and Development to ensure their email security service evolves faster than cyber criminals. We apply our Threat…
A short tutorial showing how to set up an email signature in Outlook on the Web (previously known as OWA). For free email signatures designs, visit https://www.mail-signatures.com/articles/signature-templates/?sts=6651 If you want to manage em…

685 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question