Article View: borland.public.cppbuilder.nativeapi
Article #8586Re: Drives Problem
From: Remy Lebeau (TeamB)
Date: Wed, 06 Oct 2004 22:28
Date: Wed, 06 Oct 2004 22:28
65 lines
2886 bytes
2886 bytes
"Pat" <pclancy@sasktel.net> wrote in message
news:41646f40@newsgroups.borland.com...
> Hello, I am trying to write a small program and am trying to find
> a solution to keeping some information the end user would like to
> keep. I figure the best way to do this is either through the registry
> or an INI file.
Ok so far.
> I can get the drive set once using a drive combo box and the next
> time I restart the porgram I get the proper drive but it reverts back
> to "C:" on the next restart.
Please show your actual code.
> In the "on close" section I want to use
>
> WinIni->WriteString("Drive", "CDROM", DriveComboBox1->Drive);
That is fine.
> Then in the on create section
Do not use the OnCreate event. It is a Delphi remnant that is unstable in
C++ as it can be triggered before the constructor, which is illegal in C++.
Use the actual constructor instead.
> I would like to call the last drive used with something like:
> Edit1->Text = WinIni->ReadString("Drive", "CDROM",
> DriveComboBox1->Drive);
Try this instead:
AnsiString drive = WinIni->ReadString("Drive", "CDROM", "C");
if( drive.Length() == 0 )
drive = "C";
DriveComboBox1->Drive = drive[1];
> This works for the first time I restart the program but on
> the next boot Edit1 returns to "C"
Since you did not show your actual code, particularly the section on how you
instantiate the TIniFile, I can only guess that the ini file is probably not
actually created or opened properly, thus ReadString() cannot find the value
and returns the default instead.
> It seems to me the I should be able to read this information from
> the same INI file
Correct.
> but when I try:
> DriveComboBox1->Drive = WinIni->ReadString("Drive",
> "CDROM", DriveComboBox1->Drive);
>
> I get an error ( [C++ Error] Unit1.cpp(52): E2034 Cannot
> convert 'AnsiString' to 'char')
The Drive property expects a single character, not a string. See the
example above.
Gambit
Technical Details
Message-ID:
<4164718d$1@newsgroups.borland.com>Path:
arc1-ca.pugleaf.net!g2news1.google.com!news1.google.com!news.glorb.com!npeer.de.kpn-eurorings.net!newsfeed00.sul.t-online.de!newsfeed01.sul.t-online.de!t-online.de!newsgroups.borland.com!not-for-mailReferences:
<41646f40@newsgroups.borland.com>Show Full Headers
Complete Article Headers
X-Google-Thread: 10cc67,67c77ee0f1e6771c X-Google-Attributes: gid10cc67,public X-Google-Language: ENGLISH,ASCII-7-bit From: "Remy Lebeau \(TeamB\)" <no.spam@no.spam.com> Newsgroups: borland.public.cppbuilder.nativeapi References: <41646f40@newsgroups.borland.com> Subject: Re: Drives Problem Date: Wed, 6 Oct 2004 15:28:28 -0700 Lines: 67 X-Priority: 3 X-MSMail-Priority: Normal X-Newsreader: Microsoft Outlook Express 6.00.2800.1409 X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2800.1409 NNTP-Posting-Host: 68.69.17.41 Message-ID: <4164718d$1@newsgroups.borland.com> X-Trace: newsgroups.borland.com 1097101709 68.69.17.41 (6 Oct 2004 15:28:29 -0700) Path: arc1-ca.pugleaf.net!g2news1.google.com!news1.google.com!news.glorb.com!npeer.de.kpn-eurorings.net!newsfeed00.sul.t-online.de!newsfeed01.sul.t-online.de!t-online.de!newsgroups.borland.com!not-for-mail