Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Read pascal dat files without record information

Posted on 2004-08-30
11
Medium Priority
?
742 Views
Last Modified: 2010-08-05
Hi all,

Can anybody help me - I have some old pascal dat files that I wish to access but have lost the information of the records.

Can this be done?
0
Comment
Question by:dbdp
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
  • 2
  • 2
  • +1
11 Comments
 
LVL 7

Expert Comment

by:LRHGuy
ID: 11930817
Sure, it can be done! But with a certain level of "success". You'll have to figure out the record length, probaby by trial and error or by looking at a hex dump of part of the file. Once you know the record length, it's just a matter of determining what data you want out of the record, and where in the record it is stored.

Can't say much more without a better idea of what you want to do.
0
 

Author Comment

by:dbdp
ID: 11934363
Well like I said I have some several old dat files that were part of a flat file application I had created long ago- the application is long corrupted and source code lost - all my predecessor backed upo were the dat files which data I would like to transfer to a database proper!!
0
 
LVL 7

Expert Comment

by:LRHGuy
ID: 11935235
So, to get started you might try to determine the record size. You could do this by dumping out the beginning of the file in hex, maybe with a sidebar of the ascii chars. Then you can look for the beginning of the same field (that you hopefully will recognize) in two adjacent records. Simple counting will give you the record size. You can then create a record:

rUnknown=record
  case integer of
0
Enroll in September's Course of the Month

This month’s featured course covers 16 hours of training in installation, management, and deployment of VMware vSphere virtualization environments. It's free for Premium Members, Team Accounts, and Qualified Experts!

 
LVL 7

Expert Comment

by:LRHGuy
ID: 11935275
So, to get started you might try to determine the record size. You could do this by dumping out the beginning of the file in hex, maybe with a sidebar of the ascii chars. Then you can look for the beginning of the same field (that you hopefully will recognize) in two adjacent records. Simple counting will give you the record size. You can then create a record:

const
reclen=size you determined

type
rUnknown=record
  case integer of
    0:(data:array[1..reclen] of byte);
    1:(field1: ...
        field2: ...
      )


You fill in the field types as you determine with your detective work. I usually write a little problem to read and dump the fields of the first 5 or ten records...

var
  F:file of runknown;
  R:rUnknown;

begin
  assign(F,'filename');
  reset(F);

  for I:=1 to 5 do begin
    read(f,R);
   writeln(I,': field 1 = ',R.field1);
 end;

  close(F);
end;

Then, through a simple trial and error, I can determine each field.

I hope that helps!
0
 

Author Comment

by:dbdp
ID: 11939674
It already helps a lot but having been a while since I touched pascal - could you explain further the rUnknown record a bit more?

I have determined that each record of one f the files has 6 "fields" but am not sure of what - sting - integer etc - how would I define the record?


0
 
LVL 7

Accepted Solution

by:
LRHGuy earned 1000 total points
ID: 11941285
rUnknown is just an example record. I don't know what your database is about. For example, it could be

rRecipes=record
  Name...
end;

A record definition would look something like that/this:

type
rUnknown=record
  case integer of
    0:(data:array[1..reclen] of byte);
    1:(field1: string[12]
        field2: byte;
        field3: word;
      )

Fill in the 1: section with your fields as you discover them. The 0 section keeps the record length at whatever you discovered the record length to be.

Say after you've got the hex dump, you discover the record length is 30 bytes:

const
  reclen=30;

Hopefully, you can then determine the fields. (with out a sample hex dump, this is difficult to demonstrate.) You may see that the first byte looks somewhat random, yet is followed by characters. This could be a string. The first byte may be the length of the string (not the field, necessarily).. So you examine the records, and decide to try 10 as the first field string length:
type

rUnknown=record
  case integer of
    0:(data:array[1..reclen] of byte);
    1:(field1: string[10]
        field2: byte;
        field3: word;
      )

Then you try it, running the program I showed above, to dump out the first few records:

  for I:=1 to 5 do begin
    read(f,R);
   writeln(I,': field 1 = ',R.field1);
 end;

A visual inspection may show that 10 for the length is too small...make changes and try again. Work your way field by field through the record.

Hope that helps!
0
 

Expert Comment

by:GaryStanton414
ID: 11944686
Hi. LRHGuy is correct. If you get a hex editor e.g. http://www.handshake.de/user/chmaas/delphi/download/xvi32.zip like this...open your dat file. You can imediately pick out strings which look like this for example:

♫GaryStanton

This may also be followed by a number of those boxes...any boxes after the text which are still part of the string will contain zeros on the left hand side view (hex view) in the hex editor (it is possible that they could also be representing the number 0 rather than empty space in the string). If you know what the 6 fields are this helps a lot. Example: if you know that one field is name this will of course be a string, if one field is height (in feet) then the sensible datatype to assume is byte. You can check the values of different datatypes a differnet locations in the file by using the data inspector. To do this click the tools menu, then options...click the data inspector tab and make sure that short,byte,word,integer and longint are selected...click ok...then click the tools menu and select data inspector...a small window will pop up saying data inspector...you can then click at a location on the hex view (the one with all the numbers on) and values will appear in the data inspector for each data type.

So where you think there is a number field click there and check which data type gives the most reasonable value for what the field is. E.G if you know the field is "height" (in feet) and the data inspector shows a reasonable value (e.g 6) in the inspector for a byte then it is likely to be a byte datatype. If several datatypes look reasonable then move on to the next field. E.g if shoe size was the next field and you moved along one from height...if 0 came up for byte in data inspector this is not a reasonable shoe size...you move along again and 6 comes up for a byte...this is reasonable...this means that height must have taken up 2 spaces (2 bytes) which is either a word,or an integer. Since you cant have a negative height integer is out of the question, so it must have been a word.

I hope this helps you furtur.
0
 
LVL 17

Assisted Solution

by:Wim ten Brink
Wim ten Brink earned 1000 total points
ID: 12049889
> any boxes after the text which are still part of the string will contain zeros on the left hand side view (hex view) in the hex editor

This doesn't have to be true, though. Technically, it is undefined. If the same string variable has been changed and written to disk, the second string might end with part of the first string, if the second string happens to be shorter than the second one...

Still, a hex editor can be useful to detect the layout of the file.
0
 
LVL 17

Expert Comment

by:Wim ten Brink
ID: 12272167
No objections here.
0

Featured Post

How to Use the Help Bell

Need to boost the visibility of your question for solutions? Use the Experts Exchange Help Bell to confirm priority levels and contact subject-matter experts for question attention.  Check out this how-to article for more information.

Question has a verified solution.

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

Whoever said that “a picture is worth one thousand words” observed a fact that can dramatically affect your marketing success. Most people tend to learn visually, so many publishers commonly acknowledge the effectiveness of visual learning by using…
The online market is growing at an unprecedented rate and retail eCommerce sales are expected to reach $4 trillion by 2020. Yet, the profit is not just there for the taking because you have to set yourself apart from the competition.
Do you want to know how to make a graph with Microsoft Access? First, create a query with the data for the chart. Then make a blank form and add a chart control. This video also shows how to change what data is displayed on the graph as well as form…
In this video, Percona Solution Engineer Rick Golba discuss how (and why) you implement high availability in a database environment. To discuss how Percona Consulting can help with your design and architecture needs for your database and infrastr…

715 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