[Webinar] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

text files for I/O

Posted on 1998-03-11
6
Medium Priority
?
136 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
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 
LVL 3

Accepted Solution

by:
williams2 earned 200 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

Industry Leaders: 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!

Question has a verified solution.

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

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…
Introduction Raise your hands if you were as upset with FireMonkey as I was when I discovered that there was no TListview.  I use TListView in almost all of my applications I've written, and I was not going to compromise by resorting to TStringGrid…
Exchange organizations may use the Journaling Agent of the Transport Service to archive messages going through Exchange. However, if the Transport Service is integrated with some email content management application (such as an anti-spam), the admin…
Loops Section Overview
Suggested Courses

868 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