1

I recently received some Delphi 2007 source code that was written by another developer.

I noticed when I click on a component icon in the IDE that Delphi generates the stub code as you would expect, HOWEVER it is 'stealing' the first character from the next procedure or function and placing that character in front of the generated code.

For example, when clicking on the RaizeObjects Launcher component icon in the IDE, I get this generated code with an "f" stolen from the next function (or it would be a "p" if the next item was a procedure):

fprocedure TFLogin.RzLauncher1Error(Sender: TObject; ErrorCode: Cardinal);
begin

end;

unction TFLogin.DelDir(dir: string): Boolean;
var

Of course, this corrupts my source code everytime I click on a component icon in the IDE.

I did a hex dump on the source and found that these source files only have a linefeed (0A) in them and not the Carriage Return (0D) & Linefeed (0A) that my locally produced code has (examples below).

Hex dump of a typical source file Delphi normally produces:

unit Unit1; (CR & LF)
75 6E 69 74 20 55 6E 69 74 31 3B 0D 0A

Example source code file from other person (hex dump):

unit Calc; (LF)
75 6E 69 74 20 43 61 6C 63 3B 0A

Saving the source in my editor does not fix this issue. My question is, how do I fix this issue? Is there a setting in Delphi 2007 telling it to just use linefeeds, or is there some Windows 7 setting to adjust for this issue?

Remy Lebeau
  • 555,201
  • 31
  • 458
  • 770
lgallion
  • 267
  • 3
  • 9
  • 3
    That code was probably generated in an unix environment. Open the file in an editor like notpad++ which is able to transform such files. You could also write a small Delphi program reading the file in a stringlist and write it out again... – Andre Ruebel Feb 29 '20 at 15:46
  • 1
    System.SysUtils has a function AdjustLineBreaks just for that. – Uwe Raabe Feb 29 '20 at 16:03
  • Thanks, I just wanted to make sure I wasn't overlooking a 'duh' settings option before doing a search & replace on the files. Because I had dozens of source (*.pas) files in many sub directories I found a simple, open source command line tool to do the search & replace for me. It is called "fart.exe" (yes, really - I am sure there are other/better tools available but this one worked) and the command line I used was: fart --recursive --c-style *.pas \n \r\n – lgallion Feb 29 '20 at 17:46
  • 1
    unix2dos and dos2unix are the classics of the genre – David Heffernan Mar 02 '20 at 20:35

0 Answers0