0
votes

I'm running RAD Studio Delphi XE2. Something strange appears to have been done to one of my .pas files. Many of the lines from my unit1.pas have been replaced with simply 'º' and others are missing. I am left with a small section of code from somewhere in the middle of my original file. Can I get the original unit1.pas back by somehow decompiling unit1.dcu?

Also, why would this happen? Have you heard of this before? The code runs but, obviously, I can't edit anything I can't see.

2
Just check out a fresh copy from your version control repository, or restore from backup. (It's hard to say what might have happened, because you've quoted a single character and say "others are missing".) You're never going to get the "original unit1.pas" by decompiling, because the variable names and other info simply aren't in the .dcu file. You might be able to get some salvageable logic, but it's not going to be 'unit1.pas'. - Ken White
Thanks Ken. I got a old version from the history tab fortunately I'd not done too much to it. I was using a file on a network location, I don't know if that could cause this but I'll be using a local copy from now on. - Trojanian
You really should get a real VCS. Subversion, Mercurial, or Git are all free, pretty easy to configure and use (some even with GUIs or Windows Explorer extensions to be even easier), and XE comes with support for SVN built in. It can really save your backside. :-) The IDE's _history is not a real version control system, and it stores only the last 10 copies by default (although you can increase that number). - Ken White
Actually (just edited - sorry) I'm using XE2 - but I guess it's the same. :-) I've looked into a couple of Gits. I'll pay more serious attention to them now. - Trojanian
Try opening the .pas file in another (text) editor, just in case it's a display issue, and another computer, just in case it's a problem with that computer. - Marcus Adams

2 Answers

6
votes

Even if you could decompile it, it would likely be an unmaintainable mess compared to your original.

Instead, try looking in the __History folder for your project. You should find older versions of your code. Pick the newest one ;-)

why would this happen?

Any number of reasons. Bug in the IDE? Bug in an IDE plugin or a custom component? Bug in your code that overwrites a source file, maybe?

2
votes

You cannot decompile a .dcu file to the original source. Information is lost in the translation from source code to executable code. Type declarations, variable names, method names, code layout and so on are simply not present in the compiler's output. Compilation is a one way process.

If you use revision control, you'll just be able to pull the latest version from the repository. If you don't use revision control, you've just learnt a lesson the hard way and you will never again attempt to perform software development without revision control.