2

My problem. I have a legacy Turbo Pascal program, still running on MS DOS. The original source is lost, and I need to manipulate the information found inside the .DTA files.

I would really like to access this information from .Net, read and update. The first and obvious problem is that I don’t have the original data structure for the .DTA files.

It would be ideal to read the data auto-ordering it in columns, but I’m desperate enough to sit and try to set up the fields manually.

My MAIN ISSUE is that I don’t know how to read the data and write from within .Net.

I’ve tried:

using (BinaryReader b = new BinaryReader(File.Open(l_path, FileMode.Open), Encoding.UTF8))

and

OleDbConnection myConnection = 
  new OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=c:\\;
  Extended Properties=\"text;HDR=YES;FMT=FixedLength\"");
  1. I’m able to retrieve data; unfortunately only a single column with no delimiting. So, no structure.
  2. The presence of special characters (#, @ etc.). I also don’t know which Encoding should be used.

Can somebody please help me to read and write Pascal .DTA files from .net?
Thanks, Morne

Rohit Gupta
  • 4,022
  • 20
  • 31
  • 41
  • As far as I know there is no standard format for saving data in pascal so the .DTA files could contain anything from text to binary pascal records to something that's additionally encrypted. What do you know about their format? – stmax Jun 12 '12 at 19:52

2 Answers2

0

If memory serves, the .DTA extension was the default used by the Turbo Pascal database toolkit (the exact name escapes me). I believe you can still download Turbo Pascal from the Delphi (Embarcadero) web site - if the database toolkit is included there then that's probably your best bet - in Turbo Pascal, write a converter to some other format, like CSV.

  • Appreciate your input. The other problem is that this program is still actively used (believe it!) So, converting the .DTA file to .csv will create problems. I need to seamlessly alter a few records, from the backend. That’s where the .Net program is coming into play. If I can just interpret the data file… – Morne Rossouw Jun 13 '12 at 09:30
  • Well, if you have access to Delphi and the Turbo Pascal database toolkit, writing a Delphi DLL that can read and write that legacy format is not entirely unrealistic. However, I think doing it in a foreign (relative to Embarc.) dev environment would require a prohibitive amount of reverse engineering. This is probably something you can subcontract out if you don't have the Delphi skills in house. I would offer to help if my plate wasn't so full. – 500 - Internal Server Error Jun 13 '12 at 16:18
0

Unfortunately, there probably aren't any column delimiters in the file. Turbo Pascal makes it easy to simply write a record structure to disk.

There are three big gotchas you're going to hit.

The first you have definitely hit--the file is certainly not UTF-8. Turbo Pascal predates Unicode, any text in the file is no doubt ASCII. I believe the only way you'll get that into C# is by reading it as bytes and converting it.

Second, Turbo Pascal has a datatype with no c# equivalent. Text in the file is probably stored either as an array of characters (simple enough, just discard the spaces on the end) or a string type that starts with the length. The first byte says how many characters are in the string, the next bytes are the characters. Any bytes beyond the specified length are garbage and should be discarded.

Finally, the most common floating point type in Turbo Pascal is non-standard. The thing is Turbo Pascal is from the era where most machines didn't have the math coprocessor and the normal type is considerably faster on machines that don't support the 8087 instructions.

I agree with 500 - Internal Server Error that it would be much easier to do this in Delphi or Turbo Pascal.

Loren Pechtel
  • 8,945
  • 3
  • 33
  • 45
  • Thank you guys, I appreciate the advice. This really appears to be my only option. Probably time to dig up that old Pascal book... – Morne Rossouw Jun 14 '12 at 08:23