Solved

text files for I/O

Posted on 1998-03-11
6
127 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
6 Surprising Benefits of Threat Intelligence

All sorts of threat intelligence is available on the web. Intelligence you can learn from, and use to anticipate and prepare for future attacks.

 
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

How to improve team productivity

Quip adds documents, spreadsheets, and tasklists to your Slack experience
- Elevate ideas to Quip docs
- Share Quip docs in Slack
- Get notified of changes to your docs
- Available on iOS/Android/Desktop/Web
- Online/Offline

Join & Write a Comment

Creating an auto free TStringList The TStringList is a basic and frequently used object in Delphi. On many occasions, you may want to create a temporary list, process some items in the list and be done with the list. In such cases, you have to…
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…
Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…
This video demonstrates how to create an example email signature rule for a department in a company using CodeTwo Exchange Rules. The signature will be inserted beneath users' latest emails in conversations and will be displayed in users' Sent Items…

743 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

10 Experts available now in Live!

Get 1:1 Help Now