Discussion:
Problem with TOpenDialog
(too old to reply)
Eduardo Jauch
2007-06-30 17:19:30 UTC
Permalink
Hello!

I have a project with many versions. When I need to modify my program, I
copy the directory of it with a new name and begin to work in this "new
project" (any tips to improve this I'll apreciate).

Now, something happens.

I use a TOpenDialog to open one or more files to use by my program.
Because the order in wich they are open is important, I use a struct to
store all the data of each file opened and put this struct in a TList.
So, the data on the first file open is put on the first position of the
TList, the second on the secont and go on.

On the last 14 versions of the program, this work perfectly.

But in my new version, when I click on the button that open the
TOpenDialog, all work fine. I can pick a file with no problem. The
problem occour when I click the button for the second time. The program
open the dialog, and before I can select a file, the program CLOSES!!!!

I think that some type of error on the project could do that, so, I
created a new project, put my files on it (only the source code, the
obj, tds, I erased).

But the same problem.

I don't think that is the code, because i don't change it and the others
versions work correctly yet, but here is the code that opens the Dialog:


void __fastcall TForm1::LoadApplicantClick(TObject *Sender)
{
TTime timeNow;
if(OpenDialog->Execute())
{
Memo->Lines->Add(timeNow.CurrentTime().TimeString() + "
Armazenando dados da família...");
for(int i = 0; i < OpenDialog->Files->Count; i++)
{
Memo->Lines->Add(timeNow.CurrentTime().TimeString() + " Lendo
dados do arquivo: " + OpenDialog->Files->Strings[i] + "...");
ApplicantList_.LoadFile(OpenDialog->Files->Strings[i]);
Memo->Lines->Strings[Memo->Lines->Count - 1] =
Memo->Lines->Strings[Memo->Lines->Count - 1] + " (OK)";
}
Memo->Lines->Add(timeNow.CurrentTime().TimeString() + " Dados da
família armazenados.");
Memo->Lines->Add("");
}
}

Memo -> TMemo object
OpenDialog -> TOpenDialog object
ApplicantList_ -> My object that open the file and store the data in a
TList on it.

Like you see, there's nothing wrong with the code. And because when the
OpenDialog is open, he "freeze" the program until I click the open or
cancel button, I can't see how could be my pcode.

I will try to reinstall the BCB (my version is the 6 with sp4)...

Any other tip's are welcome!

Thanks!!!
chenzero
2007-07-01 00:18:17 UTC
Permalink
Post by Eduardo Jauch
Hello!
I have a project with many versions. When I need to modify my program, I
copy the directory of it with a new name and begin to work in this "new
project" (any tips to improve this I'll apreciate).
Now, something happens.
I use a TOpenDialog to open one or more files to use by my program.
Because the order in wich they are open is important, I use a struct to
store all the data of each file opened and put this struct in a TList. So,
the data on the first file open is put on the first position of the TList,
the second on the secont and go on.
I have read your code following, it seems that only one
TOpenDiaglose pops up(multi files selection enabled I think),
so, what if the order needed is not same with the order used by
TOpenDiagnose?
whether it needs pop up TOpenDiaglog for the files one by one ?
Post by Eduardo Jauch
On the last 14 versions of the program, this work perfectly.
But in my new version, when I click on the button that open the
TOpenDialog, all work fine. I can pick a file with no problem. The problem
occour when I click the button for the second time. The program open the
dialog, and before I can select a file, the program CLOSES!!!!
usually, this problem is caused by accessing illegal resource, eg, the
memory already
freed. defaltly, it will show the errror message box . but anything could
happen if illegal access.
Post by Eduardo Jauch
I think that some type of error on the project could do that, so, I
created a new project, put my files on it (only the source code, the obj,
tds, I erased).
But the same problem.
I don't think that is the code, because i don't change it and the others
void __fastcall TForm1::LoadApplicantClick(TObject *Sender)
{
TTime timeNow;
if(OpenDialog->Execute())
{
Memo->Lines->Add(timeNow.CurrentTime().TimeString() + " Armazenando
dados da família...");
for(int i = 0; i < OpenDialog->Files->Count; i++)
{
Memo->Lines->Add(timeNow.CurrentTime().TimeString() + " Lendo dados
do arquivo: " + OpenDialog->Files->Strings[i] + "...");
ApplicantList_.LoadFile(OpenDialog->Files->Strings[i]);
Memo->Lines->Strings[Memo->Lines->Count - 1] =
Memo->Lines->Strings[Memo->Lines->Count - 1] + " (OK)";
}
Memo->Lines->Add(timeNow.CurrentTime().TimeString() + " Dados da
família armazenados.");
Memo->Lines->Add("");
}
}
Memo -> TMemo object
OpenDialog -> TOpenDialog object
ApplicantList_ -> My object that open the file and store the data in a
TList on it.
Like you see, there's nothing wrong with the code. And because when the
OpenDialog is open, he "freeze" the program until I click the open or
cancel button, I can't see how could be my pcode.
yes, if the open files operation (the code in LoadApplicantClick() ) takes
a long time, the UI will freeze until use another technology: thread
programming,

see some help in the C++ builder's help: TThread,
also, detailed description on:
http://en.wikipedia.org/wiki/Thread_(computer_science)
Post by Eduardo Jauch
I will try to reinstall the BCB (my version is the 6 with sp4)...
Any other tip's are welcome!
Thanks!!!
Eduardo Jauch
2007-07-01 09:13:02 UTC
Permalink
Post by chenzero
I have read your code following, it seems that only one
TOpenDiaglose pops up(multi files selection enabled I think),
so, what if the order needed is not same with the order used by
TOpenDiagnose?
whether it needs pop up TOpenDiaglog for the files one by one ?
Yep. :)

The case is that I had other parts of the program that seens to be more
important for meback on the time I started it ;)

But improve the selection method of files and a few others improvements
are on the way ;)
Post by chenzero
usually, this problem is caused by accessing illegal resource, eg, the
memory already
freed. defaltly, it will show the errror message box . but anything could
happen if illegal access.
I found a solution, thanks for Clayton tip... Using OleInitialize...
Post by chenzero
yes, if the open files operation (the code in LoadApplicantClick() ) takes
a long time, the UI will freeze until use another technology: thread
programming,
see some help in the C++ builder's help: TThread,
http://en.wikipedia.org/wiki/Thread_(computer_science)
I start to use Threads only in this last version...
But I'm still on begining to understand it. I'll try a look on the link
you give me :)

Thanks!

Clayton Arends
2007-07-01 02:30:54 UTC
Permalink
Did you recently install Adobe Acrobat Reader?

Your problem looks very similar to something that I encountered late last
year. There is a problem that has been identified to exist in other
languages (not just C++Builder/Delphi) where users receive unexplainable
crashes while the open dialog box is showing. The problem manifests itself
after the first time the open dialog has been shown and the user moves the
mouse over a file in the list view.

The fix is to call one of the COM initialization functions (CoInitialize,
CoInitializeEx, OleInitialize) at the beginning of program execution. You
can do this in the constructor of your main form, or WinMain(), etc. Here
is a link where this is discussed in more detail:

Tiny URL:
http://tinyurl.com/3c4ms5

Full link:
http://groups.google.com/group/borland.public.cppbuilder.vcl.components.using/
browse_frm/thread/4cceb7eabf5820d3/145d9fb4a7abcd4d#145d9fb4a7abcd4d

HTH,

- Clayton
Eduardo Jauch
2007-07-01 09:16:07 UTC
Permalink
Post by Clayton Arends
Did you recently install Adobe Acrobat Reader?
Hum... No recently... I can't remember... But seens that I install
Reader 8 after I compile the last version of the program...
Post by Clayton Arends
Your problem looks very similar to something that I encountered late last
year. There is a problem that has been identified to exist in other
languages (not just C++Builder/Delphi) where users receive unexplainable
crashes while the open dialog box is showing. The problem manifests itself
after the first time the open dialog has been shown and the user moves the
mouse over a file in the list view.
The fix is to call one of the COM initialization functions (CoInitialize,
CoInitializeEx, OleInitialize) at the beginning of program execution. You
can do this in the constructor of your main form, or WinMain(), etc. Here
http://tinyurl.com/3c4ms5
http://groups.google.com/group/borland.public.cppbuilder.vcl.components.using/
browse_frm/thread/4cceb7eabf5820d3/145d9fb4a7abcd4d#145d9fb4a7abcd4d
HTH,
- Clayton
Thanks for the tip!
I read the link you give me. Now the program is working... :)
This is very strange... rsrsrsrsrs ;)

Bye!
Loading...