views:

456

answers:

2

I thought about creating my own, but there are many details to consider to make it 100% compatible with Java .properties files, so I'm asking first.

A: 

Not a Java guy, but from what I can see .properties files are similar to .INI files in disguise; it has name=value pairs, without section names. You can use Delphi's TStringList to work with that; it has the Names and Values properties.

For example, to read the following line from a .properties file:

MyProgramData=c:\documents and settings\DR\Application Data\MyApp

I can simply use:

var
  SL: TStringList;
  MyDataPath: string;
begin
  SL :=  TStringList.Create;
  try
    SL.LoadFromFile('myapp.properties');
    MyDataPath := SL.Values['MyProgramData'];
  finally
    SL.Free;
  end;
  // Do something with MyDataPath
end;

For the overly pedantic reader, I'm not suggesting that TStringList will allow you to use the full functionality of .properties files; it may, however, be enough for what you need to do. (As I said, I'm not a Java guy.)

Ken White
That's not a valid .properties file. Backslashes are special. Read the documentation for the java.util.Properties.load() function. Equals signs can be part of the key name, but INI doesn't support that. Lines can be continued with backslashes.
Rob Kennedy
Ummm, Rob? I didn't say that was a valid .properties file anywhere, did I?
Ken White
No, I suppose you never said your example was valid. But why give invalid examples? In Java, MyProgramData's value would be "c:documents and settingsDRApplication DataMyApp". DR is interested in having 100% compatibility, so something that has no backslash support doesn't strike me as helpful.
Rob Kennedy
You're absolutely right. I *did* miss the "100% compatible" part of the OP. My bad. :-(
Ken White
+3  A: 

There used to be a Java IDE called Gel. It was written in Delphi, and it was a good IDE, so I expect it was capable of working with property files. The author has discontinued work on the project. In his blog post describing the project's cancellation, he mentions being open to the prospect of making the project open source, but it never really took off. If you ask nicely, you might get the parts of that code you're looking for.

Be skeptical of any solution you find that uses TStrings for its interface. Although that class has Names and Values properties that make it attractive as a class for working with key/value pairs, it won't be completely compatible with Java's property files. The reason is that Java allows "=" as a character in the key name, and the TStrings class detects the end of a name and the start of a value by looking for the first "=" character in a string. Furthermore, Java property files can use ":" as the separator, and they can even use ordinary whitespace.

Rob Kennedy
Gel used JNI for the properties file handling (i.e. there was no Delphi source)
DR