Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

About FileRead()

Posted on 1998-04-15
2
Medium Priority
?
267 Views
Last Modified: 2010-04-06
Can I, using FileRead(), read integers from a file and not bytes?
For example if my file is like this:

12 32

How can I read only the two numbers and not the space between them?

Thanks for your help
0
Comment
Question by:kkarnez
2 Comments
 
LVL 5

Expert Comment

by:inter
ID: 1361555
Sorry, NO(with fileread)
The easiest way is to open file and read it as a traditional pascal as  
  ReadLn(f,integer1,integer2) which reads the above line.
Of course you can do it with FileRead but not automatically, you should parse the line by yourself.
Regards, Igor

0
 
LVL 3

Accepted Solution

by:
williams2 earned 40 total points
ID: 1361556
As mentioned above, it's not possible to access data as integers directly. But you could read data like

FileRead(Handler,Byte0,1);
FileRead(Handler,Byte1,1);
FileRead(Handler,Byte2,1);
FileRead(Handler,Byte3,1);

If (Byte3 AND 127)>0 then
begin
  Dec(Byte3,127);
  i:= -(Byte3*$1000000+Byte2*$10000+byte1*$100+Byte0);
End else
  i:= Byte3*$1000000+Byte2*$10000+byte1*$100+Byte0;

But this is not a rather cool way to solve it. The FileRead operation is a lowlevel routine. Avoid using it if possible.

Regards
Williams
0

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

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…
Have you ever had your Delphi form/application just hanging while waiting for data to load? This is the article to read if you want to learn some things about adding threads for data loading in the background. First, I'll setup a general applica…
In response to a need for security and privacy, and to continue fostering an environment members can turn to for support, solutions, and education, Experts Exchange has created anonymous question capabilities. This new feature is available to our Pr…
Loops Section Overview
Suggested Courses
Course of the Month12 days, 21 hours left to enroll

971 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