Solved

About FileRead()

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

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say 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

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…
Microsoft Active Directory, the widely used IT infrastructure, is known for its high risk of credential theft. The best way to test your Active Directory’s vulnerabilities to pass-the-ticket, pass-the-hash, privilege escalation, and malware attacks …
Nobody understands Phishing better than an anti-spam company. That’s why we are providing Phishing Awareness Training to our customers. According to a report by Verizon, only 3% of targeted users report malicious emails to management. With compan…

828 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