Delphi IDE and .INI files

Hi,

I've recently upgraded to Delphi XE and am currently in a process of porting source code from Delphi 7 to XE. 

One minor irritation that I've run into is that the Delphi XE IDE opens an .ini file that's part of a project as hex.  Delphi 7 didn't behave this way -- it simply opened the .ini file as a text file for editing.  Is there an option somewhere that I've missed to get Delphi XE to treat .ini files the same way Delphi 7 did?

Many thanks,

Walter Prins
0
Andy
6/30/2011 1:40:30 PM
embarcadero.delphi.ide 3925 articles. 0 followers. Follow

7 Replies
2114 Views

Similar Articles

[PageSpeed] 22
Get it on Google Play
Get it on Apple App Store

Walter Prins wrote:

> Hi,
> 
> I've recently upgraded to Delphi XE and am currently in a process of
> porting source code from Delphi 7 to XE.
> 
> One minor irritation that I've run into is that the Delphi XE IDE
> opens an .ini file that's part of a project as hex.  Delphi 7 didn't
> behave this way -- it simply opened the .ini file as a text file for
> editing.  Is there an option somewhere that I've missed to get Delphi
> XE to treat .ini files the same way Delphi 7 did?

Just change the encoding the editor displays for this file. The
automatic detection seems to go awry sometimes. With the INI file open,
right-click on the editor and select File Format from the menu. It will
probably have "Binary" selected, just set it to ANSI.

-- 
Peter Below (TeamB)  
Don't be a vampire (http://slash7.com/pages/vampires), 
use the newsgroup archives :
http://codenewsfast.com
http://groups.google.com
0
Peter
6/30/2011 6:09:06 PM
Walter Prins wrote:

> OK... my question about preamble prompted me to go try some encoding experiments and I managed to
> fix the problem.  So in case anyone else runs into this problem, this is what I've done to get
> around it:  Convert your .ini files to UTF 8 (without BOM) encoding.  I did this using Notepad++
> (open source text editor) but you can obviously use whatever editor you want that will support
> the correct conversion.  In Notepad++ the actions are 1) Open file 2) Click "Encoding"->"Convert
> to UTF8 without BOM".  3) Cl ick "File"->"Save".  That's it.  After that, Delphi itself correctly
> opens the file and the file will still be readable by e.g. IniFiles.TIniFile.  Note: Encoding as
> plain UTF8 (including BOM) does not work -- although Delphi will correctly open the file,
> TIniFile will not.  So bottom line, use the UTF without BOM encoding.

Hi Walter,
First of all, glad you got it fixed, secondly I'm sorry I didn't pay attention to this thread
before.
There was a similar case in March this year, see:
https://forums.embarcadero.com/thread.jspa?messageID=332176&tstart=0#332176
The culprit in that case was $01 characters in the source file, which confused the editor and
resulted in the hex display.
Do you still have the problematic file and could you check whether it contains characters in the
range $00 to $1F except tab($09), cr($0D) or lf($0A). Or if you can, upload it to forum
embarcadero.public.attachements.
It would also be interesting to know with what editor it was last edited (external editor or delphi
or saved with TIniFile).

Cheers
Tom


-- 
Tom Brunberg
0
Tom
7/5/2011 10:52:39 AM
Hi Tom,

Thanks for posting back, however I might've been a bit hasty in declaring the issue fully resolved, since after reading your response I inspected things a little more closely and found the problem wasn't fully resolved after all (see below).

Nevertheless your comments explained what is going on -- the issue was becuase the INI file in question actually contains a XOR/key encrypted username & password, which is currently stored in the INI as-is as a quoted string.  The short of the long is that these values contain control characters and although I've not checked the exact ordinal values of the characters you're no doubt correct that one or more of these are causing the Delphi IDE to infer that the file is in fact a binary file.  

Furthermore, my suggestion to convert the file to UTF8 doesn't actually work as it actually "corrupts" the fields, since the ordinal byte/character values are obviously changed during conversion which makes it impossible for the routine to decode them again correctly.  

Also I noticed that repopulating the fields using TIniFile appears to rewrite the file again with ANSI encoding.

However, taking a step back I'm thinking that the real problem here is the fact that non-text characters are being put into an INI file.  Probably the best solution is for me to avoid these characters in the INI file in the first place and instead perhaps I should encode the encrypted strings as hex text (or at least readable text only of some sort) before storing in the INI file.

I'll post back once I've solved this issue satisfactorily.

Thanks again for your response,

Walter

> {quote:title=Tom Brunberg wrote:}{quote}
> Hi Walter,
> First of all, glad you got it fixed, secondly I'm sorry I didn't pay attention to this thread
> before.
> There was a similar case in March this year, see:
> https://forums.embarcadero.com/thread.jspa?messageID=332176&tstart=0#332176
> The culprit in that case was $01 characters in the source file, which confused the editor and
> resulted in the hex display.
> Do you still have the problematic file and could you check whether it contains characters in the
> range $00 to $1F except tab($09), cr($0D) or lf($0A). Or if you can, upload it to forum
> embarcadero.public.attachements.
> It would also be interesting to know with what editor it was last edited (external editor or delphi
> or saved with TIniFile).

Edited by: Walter Prins on Jul 5, 2011 7:31 AM
0
Andy
7/5/2011 2:32:17 PM
Hi Peter,

Thanks for you response, however:

> {quote:title=Peter Below wrote:}{quote}
> > Just change the encoding the editor displays for this file. The
> automatic detection seems to go awry sometimes. With the INI file open,
> right-click on the editor and select File Format from the menu. It will
> probably have "Binary" selected, just set it to ANSI.

I've tried this, but what then happens is that the display in Delphi XE remains as-is, (e.g. hex).  Then when I close the file, Delphi prompts to to save the change.  If I accept, what happens is that the hex is saved as text to the file, so then I have a file that's totally unusable...  Fortunately there's such a thing as version control, but after reverting the file we're back where we started, e.g. opening the file again displays it as hex and if you right click and click on "File format" the format se
lected is again "Binary".

Is there some preamble or header or magic number that I can add to the INI file to trick Delphi into reading the file properly?  

[time passes...]

*[Edit: Please note this conclusion is not quite correct, please see later posts in this thread.]*
OK... my question about preamble prompted me to go try some encoding experiments and I managed to fix the problem.  So in case anyone else runs into this problem, this is what I've done to get around it:  Convert your .ini files to UTF 8 (without BOM) encoding.  I did this using Notepad++ (open source text editor) but you can obviously use whatever editor you want that will support the correct conversion.  In Notepad++ the actions are 1) Open file 2) Click "Encoding"->"Convert to UTF8 without BOM".  3) Cl
ick "File"->"Save".  That's it.  After that, Delphi itself correctly opens the file and the file will still be readable by e.g. IniFiles.TIniFile.  Note: Encoding as plain UTF8 (including BOM) does not work -- although Delphi will correctly open the file, TIniFile will not.  So bottom line, use the UTF without BOM encoding.  

Cheers

Walter

Edited by: Walter Prins on Jul 5, 2011 3:21 AM

Edited by: Walter Prins on Jul 5, 2011 8:15 AM
0
Andy
7/5/2011 3:16:11 PM
Walter Prins wrote:

> Hi Tom,
> 
> Thanks for posting back, however I might've been a bit hasty in declaring the issue fully
> resolved, since after reading your response I inspected things a little more closely and found
> the problem wasn't fully resolved after all (see below).
> 
> Nevertheless your comments explained what is going on -- the issue was becuase the INI file in
> question actually contains a XOR/key encrypted username & password, which is currently stored in
> the INI as-is as a quoted string.  The short of the long is that these values contain control
> characters and although I've not checked the exact ordinal values of the characters you're no
> doubt correct that one or more of these are causing the Delphi IDE to infer that the file is in
> fact a binary file.
> 
> Furthermore, my suggestion to convert the file to UTF8 doesn't actually work as it actually
> "corrupts" the fields, since the ordinal byte/character values are obviously changed during
> conversion which makes it impossible for the routine to decode them again correctly.
> 
> Also I noticed that repopulating the fields using TIniFile appears to rewrite the file again with
> ANSI encoding.
> 
> However, taking a step back I'm thinking that the real problem here is the fact that non-text
> characters are being put into an INI file.  Probably the best solution is for me to avoid these
> characters in the INI file in the first place and instead perhaps I should encode the encrypted
> strings as hex text (or at least readable text only of some sort) before storing in the INI file.
> 
> I'll post back once I've solved this issue satisfactorily.
> 
> Thanks again for your response,
> 
> Walter
> 
> > {quote:title=Tom Brunberg wrote:}{quote}
> > Hi Walter,
> > First of all, glad you got it fixed, secondly I'm sorry I didn't pay attention to this thread
> > before.
> > There was a similar case in March this year, see:
> > https://forums.embarcadero.com/thread.jspa?messageID=332176&tstart=0#332176
> > The culprit in that case was $01 characters in the source file, which confused the editor and
> > resulted in the hex display.
> > Do you still have the problematic file and could you check whether it contains characters in the
> > range $00 to $1F except tab($09), cr($0D) or lf($0A). Or if you can, upload it to forum
> > embarcadero.public.attachements.
> > It would also be interesting to know with what editor it was last edited (external editor or
> > delphi or saved with TIniFile).
> 
> Edited by: Walter Prins on Jul 5, 2011 7:31 AM

Ok Walter, that explains the problem fully.

Take a look at TIniFile.WriteBinaryStream ans TIniFile.ReadBinaryStream.
Those methods write and read hex representations of binary data, so I think that would be the
easiest solution.

Cheers
Tom



-- 
Tom Brunberg
0
Tom
7/5/2011 3:29:32 PM
> {quote:title=Tom Brunberg wrote:}{quote}
> 
> Ok Walter, that explains the problem fully.
> 
> Take a look at TIniFile.WriteBinaryStream ans TIniFile.ReadBinaryStream.
> Those methods write and read hex representations of binary data, so I think that would be the
> easiest solution.

Thanks for that suggestion, indeed that's the proper way to deal with binary data in an INI file.  However, I'll note for the record that it's in fact possible to get the things working even with the quoted strings containing special characters (somewhat as I previously described using some form of Unicode INI file), but there are a couple of points to be aware of:

1.) The only Unicode format that also work well with TInifile, is "Little Endian UCS-2".  TInifile (for reasons I've not investigated) fails to properly read the text file if the INI file is in any of the other formats supported by the Delphi XE IDE. (e.g, none of UTF8, Little Endian UCS-4, Big Endian UCS4, Little Endian UCS2 are properly read by TINIFile.)  

2.) Depending on usage, any quoted special characters in the INI file may not work anymore as expected if directly converted from ASCII, so you'll have to re-write/re-encode the fields to fix them after converting the INI file from ASCII to Little Endian UCS-2 encoding.

3.) Even though TInifile uses the Windows Widestring API's under the hood to do the file IO, you need to nevertheless ensure that the entire INI file is unambiguously Unicode (and to be precise, in fact "Little Endian UCS-2") before attempting to write/update it using TINifile, since the Windows Widestring API's will (as might be expected) write 8-bit ASCII to a file if the file appears to be non-unicode, but also when the file is non-existant.  The upshot of this is that you cannot use TINIFile itself to
 convert from ASCII to Unicode.  For more about this type of issue, see here: http://ur.ly/NpIB

If anyone wants test cases or demonstrations of the TINifile behaviour and failures with various types of file encodings, I'd be happy to knock them up and post to attachements or whatever.

Walter
0
Walter
7/8/2011 3:00:56 PM
"Tom Brunberg" <nospam@to.me> wrote in message 
news:375108@forums.embarcadero.com...

> Take a look at TIniFile.WriteBinaryStream ans
> TIniFile.ReadBinaryStream. Those methods write
> and read hex representations of binary data, so I
> think that would be the easiest solution.

The downside is those methods utilize hex encoding, which doubles the 
storage space of the binary data.  If size is an issue, then consider using 
base64, yEnc, or any other binary text encoding that utilizes compression.

-- 
Remy Lebeau (TeamB)
0
Remy
7/9/2011 7:22:26 AM
Reply:

Similar Artilces:

VS ide / delphi ide key map
I'm quit lost in VS ide, F9 run, F8 / F7 Ctrl+Alt+P for tool pallet and the fast find when you type component name F11 to switch to code view / object inspector, the ability to navigate in the object inspector with tab and writing property name. Will someone make a Delphi to VS guide? -- Henning Swiboda wrote: > I'm quit lost in VS ide, F9 run, F8 / F7 > Ctrl+Alt+P for tool pallet and the fast find when you type component > name > F11 to switch to code view / object inspector, the ability to navigate > in the object inspector with tab and writing propert...

Delphi 2006 vs Delphi 2009 IDE stability
Hello, all. I have medium sized project which includes about 20Mb of source code (just size of *.pas files). I use Delphi 2006. There are third party component suites JVCL, DevExpress Bars, Pegasus Imaging. All updates applied. The main problem is IDE stability. About four..five times a day IDE become unstable after intensive usage of code insight functions (most often I press Ctrl+Space key). The best outcome is that I have to save everything and restart the IDE. The worst outcome is when IDE stalls or falls into endless loop of error messages and any unsaved work is lost. OS...

Comparison between Visual Studio 2008 IDE and Delphi 2010 IDE?
Hi, I wonder which is more programmer friendly. Especially for syntax highlighting and fast code writting, viewing.. Thanks.. Mehmet Fide wrote: > Hi, > > I wonder which is more programmer friendly. Especially for syntax > highlighting and fast code writting, viewing.. > > > Thanks.. See "RAD Studio 2010 vs. Visual Studio 2010" in non-technical group. -- Warm Regards, Lee ...

Delphi IDEs
Is it possible to write applications for Android and touch sensitive screens with Delphi XE4 or later versions of Delphi? Is it possible to write applications for Windows 8 and touch sensitive screens with Delphi XE4 and later versions of Delphi? Pier Pier wrote: > Is it possible to write applications for Android and touch sensitive > screens with Delphi XE4 or later versions of Delphi? iOS support was added in XE4. Android support was added in Delphi XE5. > Is it possible to write applications for Windows 8 and touch sensitive > screens with Delphi XE4 an...

Re-associate Delphi files with the IDE
Hi, I've noticed that all my .PAS and other Delphi files are no longer associated with Delphi. Usually after install I'm able to double click these files and the open IDE will load the file. If I use the Open With default option it tries to launch a new IDE everytime I double click one of the Delphi files. Is there a way to get it back to how it normally behaves without re-installing Delphi? Thanks Johann Campbell wrote: > Hi, I've noticed that all my .PAS and other Delphi files are no > longer associated with Delphi. Usually after install I'm able to > doubl...

Re: Where is data form wizard in Delphi 2009? [pubic.delphi.ide]
This message is in MIME format. Since your mail reader does not understand this format, some or all of this message may not be legible. --JivePart=_21560.zeB8CwDOH5aMJzMl Content-Type: text/plain; charset="Utf-8" Sample picture showing drag and drop from persistent fields edit window. (Any TField in any TDataset should work, TSomeKindofTable, or TSomeKindofQuery. Warren --JivePart=_21560.zeB8CwDOH5aMJzMl Content-Type: image/jpeg; name="drag_and_drop_from_persistent_fields_editor.jpg" Content-Transfer-Encoding: base64 Content-Disposition: attachment; ...

Delphi 2009 IDE corrupts project file?
I did a build and maybe an install on a Delphi project that is not a design time project. The units in the project have disappear twice now after building the project. I let Delphi convert the project instead of creating a new project and adding the units. Has anyone else had project corruption problems with Delphi 2009? Larry Griffiths ...

Is it posible to configure Delphi XE3 IDE to use Delphi 7 compiler/debuger
Hi! Like many other developer out there I have several project which has been developed with older version of Delphi (Delphi 7). Since theese projects rely on some components which are not compatible with newer versions of Delphi (no newer versions available) I'm forced to do any maintnance on theese projects using Delphi 7. Another solution would be to find replacment components which would provide me with same capabilities and work with latest versions of Delphi. But this would probbably require compleete rewritings of my projects (lots and lots of work). So currently I'm using...

Trackpad scroll down in IDE goes to end of file: Delphi XE6
Hello, When I use the trackpad to scroll down a file in XE6, it goes to the end of the file. Scrolling up works fine. I've tested this on other applications - eg a very large file in Word - and it works fine. Has anyone else seen this problem and managed to fix it? I'm running windows 7 on a mac using Parallels 10. Thanks, Ian I don't have that problem, but something similar: when I scroll with the trackpad (say, a swipe down) the code sometimes scrolls a long way down, then up again - and sometimes down and up again after that.) Chances are it's somethin...

Delphi 6 IDE, Open Project does not sort the file name
Hi, I am using Delphi 6 IDE on Windows XP, when I open the project it does not sort the file names by alphabatic, I Click on "View Menu-- Detail -- click on Name" . When I go back to open project, it goes back to its normal sorting... Where do I need to make change, so everytime I open open project it will open in alphabatic order. Any help will be highly apprecaited! Thanks. Sam > {quote:title=samir patel wrote:}{quote} > Hi, > > I am using Delphi 6 IDE on Windows XP, when I open the project it does not sort the file names by alphabatic, > I ...

Delphi 2010 IDE can not open file or project (no reponse)
Hi there I have a strange problem with my Delphi 2010. I can not Open File or Open Projects. when pressing this buttons there is no response from delphi. (but i can open new project r file and i also can open the project from favorite list) Thanks Roni ...

Opening up a PAS file opens up another instance of Delphi XE IDE... [Edit]
Here's the problem: When I double click on a .Pas file. a new Delphi XE IDE opens up. Is there a way to open up the file inside of the Delphi XE IDE that is currently open? Edited by: Joseph Trapani on Jan 31, 2012 4:04 PM > Here's the problem: > When I double click on a .Pas file. a new Delphi XE IDE opens up. > Is there a way to open up the file inside of the Delphi XE IDE that is > currently open? > > Edited by: Joseph Trapani on Jan 31, 2012 4:04 PM Drag and drop the file onto the IDE? BTW: I have my .PAS files set to open in a text editor ...

XE7 / Delphi
If I right-click, say TTouches, in the IDE and select [Find Declaration] I am getting an error, "Unable to locate file FMX.Types.pas". I see similar errors (for FXM.Xxx and VCL.Xxx units) while debugging. How can I fix this? I am SERIOUSLY hoping that I'm not going to have to manually add a series of directories to search paths, or anything like that. Any help [as always] is much appreciated. Thanks! ...

Delphi needs this: Designtime 'tasks' panes in MS Visual Web Developer 2008 [picture]
This message is in MIME format. Since your mail reader does not understand this format, some or all of this message may not be legible. --JivePart=_8bd4.zeB8CwDOH5aMJzMl Content-Type: text/plain; charset="Utf-8" --JivePart=_8bd4.zeB8CwDOH5aMJzMl Content-Type: image/jpeg; name="WeNeedThis.jpg" Content-Transfer-Encoding: base64 Content-Disposition: attachment; filename="WeNeedThis.jpg" iVBORw0KGgoAAAANSUhEUgAAARcAAAEaCAYAAAA7TRMKAAAABHNCSVQICAgIfAhkiAAAAAlwSFlz AAAL1wAAC9cBJXXS8AAAABl0RVh0U29mdHdhcmUAd3d3Lmlua3NjYXBlLm9yZ5vuPBoAACAASURB VHic...

Web resources about - Delphi IDE and .INI files - embarcadero.delphi.ide

Delphi - Wikipedia, the free encyclopedia
... an archaeological site and a modern town in Greece on the south-western spur of Mount Parnassus in the valley of Phocis . The site of Delphi ...

Delphi Automotive (@DelphiAuto) on Twitter
Log in Sign up You are on Twitter Mobile because you are using an old version of Internet Explorer. Learn more here Delphi Automotive @ DelphiAuto ...

Delphi Connect for Verizon on the App Store on iTunes
Get Delphi Connect for Verizon on the App Store. See screenshots and ratings, and read customer reviews.


Audi working with Delphi to develop autonomous car tech
Audi is developing an iPad-sized device that will pack all the necessary computing power for a self-driving car

US approves China company's acquisition of Delphi biz
The Committee on Foreign Investment in the United States has formally approved the acquisition of Delphi's global production of braking systems ...

Verizon And Delphi Officially Launch Vehicle Diagnostics Service - $250 For The Module, $5 A Month On ...
If you're a car nut, a paranoid parent, or a small business owner looking to do a little, uh, company vehicle economy analysis, Verizon's teamed ...

Watch out Google: Delphi gives Ars a ride in its self-driving car
The automotive components maker gave Ars a preview ride around the neighborhood. MOUNTAIN VIEW, CA—On Thursday morning I met with Delphi at its ...

The skinny on Delphi's autonomous road trip across the United States
Filed under: Green , Videos , Autonomous Last week, Delphi's autonomous car became the first to complete a coast-to-coast trip across the United ...

Delphi partners with WiTricity on automated wireless charging system
One could easily argue that parking between the white lines at any local hangout presents a challenge for some inexperienced drivers. So, why ...

Resources last updated: 11/23/2015 12:30:36 AM