Solved

About FileRead()

Posted on 1998-04-15
2
239 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 10 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

ScreenConnect 6.0 Free Trial

At ScreenConnect, partner feedback doesn't fall on deaf ears. We collected partner suggestions off of their virtual wish list and transformed them into one game-changing release: ScreenConnect 6.0. Explore all of the extras and enhancements for yourself!

Question has a verified solution.

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

This article explains how to create forms/units independent of other forms/units object names in a delphi project. Have you ever created a form for user input in a Delphi project and then had the need to have that same form in a other Delphi proj…
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…
Although Jacob Bernoulli (1654-1705) has been credited as the creator of "Binomial Distribution Table", Gottfried Leibniz (1646-1716) did his dissertation on the subject in 1666; Leibniz you may recall is the co-inventor of "Calculus" and beat Isaac…
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …

770 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