[x]
Posted via EE Mobile

Search, ask, and monitor your questions on the go with EE Mobile. Visit Experts Exchange from your mobile device and never be out of touch again.

Question
[x]
Attachment Details
[x]
The Solution Rating System

With so many solutions, how can you tell which solutions are most likely to help you and which ones are not? To provide you with a tool to use, we rate our solutions based on various elements that most accurately determine if a solution is a quality solution. To explain what factors affect the solution rating, here are the elements we take into consideration when formulating our solution rating.

  • The Grade of the Solution
  • The Zone Rank of the Expert Providing the Solution
  • The Number of Author and Expert Comments
  • The Number of Experts Contributing
  • The Feedback of the Community

Your Input Matters
Because of the way the system is set up, the most important variable in this equation is you. As a member of Experts Exchange, you are able to cast your vote on the quality of the solutions in regard to how complete, accurate, helpful and easy to understand each solution is. When you provide your feedback, each rating is adjusted accordingly. So, if you see a solution that has a poor rating that you think is a good solution, let us know by rating it. As you do, the rating will be adjusted and will become more accurate for other members of our site.

If you have any suggestions that you would like to make for our rating system, please ask a question in the Suggestions Zone of Community Support.

Thank you!

8.2

How to read a binary file into a string?

Asked by Grendel666 in Delphi Programming

Tags: binary, file, read

Hi all,

I'm trying to write a small app that examines all files in a specified directory and gets a certain value from each file, then output the results somewhere (memo pad at the moment).

I have binary files (Oracle Forms compile .fmx files, in case you're interested) in which I want to search for the word 'Revision' and get the numbers just after the word.

I have tried ReadLn until EOF, but as it's a binary file, I suspect that there is an EOF marker somewhere in the file that stops before the code finds 'Revision'.  I used ReadLn to add each line to a string variable (have tried widestring as well) to store the whole file in memory.  But when the string is examined (using pos) for the word 'Revision', it does not exist, even though when I open the file in Wordpad (or Notepad) I can clearly see it.

Here's a snippet of code for the ReadLn :

var
    fFileIn : TextFile;
    sLine : widestring; (or string)
    nPos : integer;
    bFinished : boolean;
    sRevision : string;
begin
.....
        bFinished := False;
        Repeat
            ReadLn(fFileIn, sLine);
            sLine := Trim(sLine);

            nPos := pos('Revision', sLine);
            sRevision := 'Unknown'
            IF nPos <> 0 THEN
               (get the revision number by looking at the next few chars)
                ....
                bFinished := True;
            end; // IF
        Until EOF(fFileIn) OR bFinished;

When looking in WordPad, the word 'Revision' is completely on one line (i.e. not split over two lines).
sLine does never contain any part of 'Revision', even though it exists in the file.

I then tried using BlockRead, but that gives the same problem (as well as destroying my local loop variable and other localstring variables).

Here's the blockread snippet of code :

var
    fFileIn : File;
    sFile : string;
    sTemp : char;
begin
.....

        Repeat
                blockread(fFileIn, sTemp, 1);
                sFile := sFile + sTemp;
        Until EOF(fFileIn);

Some of the files I am searching through do return the word 'Revision', but some don't, for each version of the code.

I thought about seeing what the value of each character is and dispensing with any below an ASCII value of 65 ('A'), but then I'll be getting rid of the EOF marker, so the code will just loop forever, unless I put some kind of counter in.  I did try this with a counter of 5000 (the word appears about 4600), but even that didn't get me anywhere.

Any ideas would be gratefully recieved.  (Or the names of any Windows apps that would do this for me!)

I can increase the points depending on the answer.  ;)

Thanks,

Grendel.
[+][-]02/17/05 02:50 AM, ID: 13333284Accepted Solution

View this solution now by starting your 30-day free trial. Setting up your free trial is quick, easy, and secure. We will return you to this solution, unlocked, when you're done.

About this solution

Zone: Delphi Programming
Tags: binary, file, read
Sign Up Now!
Solution Provided By: Imthiyaz_ph
Participating Experts: 6
Solution Grade: A
 
[+][-]02/17/05 02:47 AM, ID: 13333275Expert Comment

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 30-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]02/17/05 03:06 AM, ID: 13333392Assisted Solution

Assisted solutions are selected by the member who asked the question as a comment that contributed to their question's solution.

Start your 30-day free trial to view this Assisted Solution or ask the Experts your question.

 
[+][-]02/17/05 03:13 AM, ID: 13333419Assisted Solution

Assisted solutions are selected by the member who asked the question as a comment that contributed to their question's solution.

Start your 30-day free trial to view this Assisted Solution or ask the Experts your question.

 
[+][-]02/17/05 06:28 AM, ID: 13334819Expert Comment

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 30-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]02/17/05 03:19 PM, ID: 13340523Assisted Solution

Assisted solutions are selected by the member who asked the question as a comment that contributed to their question's solution.

Start your 30-day free trial to view this Assisted Solution or ask the Experts your question.

 
[+][-]02/18/05 12:59 AM, ID: 13343555Author Comment

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 30-day free trial to view this Author Comment or ask the Experts your question.

 
 
Loading Advertisement...
20091111-EE-VQP-92