Solved

text files for I/O

Posted on 1998-03-11
6
128 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
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Introduction The parallel port is a very commonly known port, it was widely used to connect a printer to the PC, if you look at the back of your computer, for those who don't have newer computers, there will be a port with 25 pins and a small print…
Hello everybody This Article will show you how to validate number with TEdit control, What's the TEdit control? TEdit is a standard Windows edit control on a form, it allows to user to write, read and copy/paste single line of text. Usua…
This Micro Tutorial will teach you how to censor certain areas of your screen. The example in this video will show a little boy's face being blurred. This will be demonstrated using Adobe Premiere Pro CS6.
This Micro Tutorial will give you a basic overview how to record your screen with Microsoft Expression Encoder. This program is still free and open for the public to download. This will be demonstrated using Microsoft Expression Encoder 4.

910 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

Need Help in Real-Time?

Connect with top rated Experts

16 Experts available now in Live!

Get 1:1 Help Now