 |
BorlandTalk.com Borland discussion newsgroups
|
| View previous topic :: View next topic |
| Author |
Message |
Oren Halvani Guest
|
Posted: Tue Jun 22, 2004 12:07 am Post subject: OpenDialog, function that saves the last opend folder.. |
|
|
hi dear builders,
i've got a strange problem..
i'm saving the last opend folder where the user opend a file via
"InitialDir"..
it works..but only sometimes, if it's not work than OpenDialog starts from
the "current" directory..for example "C:"
how can it be..? Is something wrong with my function..?
Oren
/***************************************************/
#include <Registry.hpp>
void __fastcall TfrmMainUnit::Button1Click(TObject *Sender)
{
TRegistry* reg = new TRegistry;
String RegistryKey = "\Software\Halvani\MyProg2.1\";
reg->OpenKey(RegistryKey, true);
OpenDialog->InitialDir = reg->ReadString("OpenDialog_Folder");
reg->CloseKey();
if(OpenDialog->Execute())
{
RichEdit1->Lines->LoadFromFile(OpenDialog->FileName);
RichEdit1->SetFocus(); // jump to top line..
Caption = "MyProg 2.1 - " + OpenDialog->FileName;
}
reg->OpenKey(RegistryKey, true);
reg->WriteString("OpenDialog_Folder", OpenDialog->InitialDir);
reg->CloseKey();
delete reg;
}
/***************************************************/
|
|
| Back to top |
|
 |
JD Guest
|
Posted: Tue Jun 22, 2004 5:56 am Post subject: Re: OpenDialog, function that saves the last opend folder.. |
|
|
"Oren Halvani" <NoSpam (AT) fdtd (DOT) com> wrote:
| Quote: | [...] i'm saving the last opend folder where the user opend
a file via "InitialDir". it works..but only sometimes
|
You should look at the help for TOpenDialog::InitialDir. I
suspect that in certain cases that property actually gets
altered by the VCL.
However, that's not the ultimate problem. I see that you fetch
the InitialDir from the Registry and then you write it (presumably
the same string) back to the Registry and that's not what you
want. You want to save the path to the new file in the
Registry - not the InitialDir - and that should only happen if
the dialog is executed:
void __fastcall TfrmMainUnit::Button1Click(TObject *Sender)
{
TRegistry* reg = new TRegistry;
String RegistryKey = "\Software\Halvani\MyProg2.1\";
reg->OpenKey( RegistryKey, true );
OpenDialog->InitialDir = reg->ReadString( "OpenDialog_Folder" );
// No need to CloseKey here because you might use the key
// again. Besides, TRegistry's destructor automatically
// closes the key for you so you only need to delete reg.
// reg->CloseKey();
if( OpenDialog->Execute() )
{
RichEdit1->Lines->LoadFromFile(OpenDialog->FileName);
RichEdit1->SetFocus(); // jump to top line..
Caption = "MyProg 2.1 - " + OpenDialog->FileName;
String NewPath = ExtractFilePath( OpenDialog->FileName );
if( NewPath.Length() > 3 )
{
while( NewPath.IsPathDelimiter(NewPath.Length()) ) NewPath.Delete( NewPath.Length(), 1 );
}
reg->WriteString( "OpenDialog_Folder", NewPath );
}
// reg->CloseKey();
delete reg;
}
~ JD
|
|
| Back to top |
|
 |
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
|