 |
BorlandTalk.com Borland discussion newsgroups
|
| View previous topic :: View next topic |
| Author |
Message |
dzeidzei Guest
|
Posted: Wed Feb 15, 2006 8:03 pm Post subject: Password dialog for application? |
|
|
Hi,
I'm stucked with this. Please help.
I'd like to write a liitle password protected app and don't know how to do it.
I'd like to have a password form (with username and password fields) and if they are corrct the main app form will show up (and password form will close itself).
What will the logick be?
Thanks!
-dzeidzei |
|
| Back to top |
|
 |
Liz Albin Guest
|
Posted: Wed Feb 15, 2006 8:03 pm Post subject: Re: Password dialog for application? |
|
|
On 15 Feb 2006 11:20:48 -0700, dzeidzei wrote:
| Quote: | Hi,
I'm stucked with this. Please help.
I'd like to write a liitle password protected app and don't know how to do it.
I'd like to have a password form (with username and password fields) and if they are corrct the main app form will show up (and password form will close itself).
What will the logick be?
Thanks!
|
I'm fairly sure that this isn't really a C++ question, and my answer
certainly isn't
bcb 6 and later have a password dialog. Try using that.
--
liz |
|
| Back to top |
|
 |
Remy Lebeau (TeamB) Guest
|
Posted: Wed Feb 15, 2006 10:03 pm Post subject: Re: Password dialog for application? |
|
|
"dzeidzei" <dzeidzei (AT) suolakaivos (DOT) com> wrote in message
news:43f37f10$1 (AT) newsgroups (DOT) borland.com...
| Quote: | I'd like to have a password form (with username and password fields)
and if they are corrct the main app form will show up (and password
form will close itself). What will the logick be?
|
Edit the project's WinMain() function directly to show the password form
modally before creating the MainForm, ie:
--- Project1.cpp ---
#include "PasswordForm.h"
int WINAPI WinMain(HINSTANCE, HINSTANCE, LPSTR, int)
{
//...
Application->Initialize();
TPasswordForm *Form = new TPasswordForm(NULL);
int Result = Form->ShowModal();
delete Form;
if( Result == mrOk )
{
Application->CreateForm(__classid(TMainForm), &MainForm);
//...
Application->Run();
}
//...
return 0;
}
Do all of the validation inside of the TPasswordForm class, and set its
ModalResult property to a non-zero value accordingly.
Gambit |
|
| Back to top |
|
 |
dzeidzei Guest
|
Posted: Thu Feb 16, 2006 7:03 pm Post subject: Re: Password dialog for application? |
|
|
Thanks again Gambit!
"Remy Lebeau \(TeamB\)" <no.spam (AT) no (DOT) spam.com> wrote:
| Quote: |
Edit the project's WinMain() function directly to show the password form
modally before creating the MainForm, ie:
--- Project1.cpp ---
#include "PasswordForm.h"
int WINAPI WinMain(HINSTANCE, HINSTANCE, LPSTR, int)
{
//...
Application->Initialize();
TPasswordForm *Form = new TPasswordForm(NULL);
int Result = Form->ShowModal();
delete Form;
if( Result == mrOk )
{
Application->CreateForm(__classid(TMainForm), &MainForm);
//...
Application->Run();
}
//...
return 0;
}
Do all of the validation inside of the TPasswordForm class, and set its
ModalResult property to a non-zero value accordingly.
Gambit
|
|
|
| Back to top |
|
 |
Torsten Franz Guest
|
Posted: Fri Feb 17, 2006 10:03 am Post subject: Re: Password dialog for application? |
|
|
| Quote: | TPasswordForm *Form = new TPasswordForm(NULL);
int Result = Form->ShowModal();
delete Form;
|
Hi Remy,
as you are seen as kind of a guru in this board by most people
(especially by the novice/amateur programmers),
I'd like to see you to use best practice techniques as well in your
examples to lead those programmers into the right direction,
otherwise old behaviours will not die :-)
In this case the raw memory management new...delete caught my eyes
and I'd would have expected to see the smart pointer solution
#include <memory>
....
std::auto_ptr<TPasswordForm> Form(new TPasswordForm(NULL));
if(mrOk == Form->ShowModal())
{
}
Ciao
Torsten |
|
| Back to top |
|
 |
David Ayre Guest
|
Posted: Fri Feb 17, 2006 8:03 pm Post subject: Re: Password dialog for application? |
|
|
What's wrong with new ... delete anyway?
To my mind it made Remy's explanation of the point in question
very clear and easy to understand. I would have found that the
use of the auto_ptr confused the issue, as everybody understands
new ... delete.
Cheers,
David
"Torsten Franz <FirstName_LastName at agilent dott" <com>> wrote:
| Quote: |
TPasswordForm *Form = new TPasswordForm(NULL);
int Result = Form->ShowModal();
delete Form;
Hi Remy,
as you are seen as kind of a guru in this board by most people
(especially by the novice/amateur programmers),
I'd like to see you to use best practice techniques as well in your
examples to lead those programmers into the right direction,
otherwise old behaviours will not die :-)
In this case the raw memory management new...delete caught my eyes
and I'd would have expected to see the smart pointer solution
#include <memory
...
std::auto_ptr<TPasswordForm> Form(new TPasswordForm(NULL));
if(mrOk == Form->ShowModal())
{
}
Ciao
Torsten |
|
|
| Back to top |
|
 |
Alan Bellingham Guest
|
Posted: Fri Feb 17, 2006 9:03 pm Post subject: Re: Password dialog for application? |
|
|
"David Ayre" <davidcayre (AT) ntlworld (DOT) com> wrote:
| Quote: | What's wrong with new ... delete anyway?
|
It's a potential error point.
| Quote: | To my mind it made Remy's explanation of the point in question
very clear and easy to understand. I would have found that the
use of the auto_ptr confused the issue, as everybody understands
new ... delete.
|
But not, it would seem, why to avoid them when possible, as you have
just so ably demonstrated.
Alan Bellingham
--
Team Thai Kingdom
<url:http://www.borland.com/newsgroups/> Borland newsgroup descriptions
<url:http://www.borland.com/newsgroups/netiquette.html> netiquette |
|
| Back to top |
|
 |
Remy Lebeau (TeamB) Guest
|
Posted: Sat Feb 18, 2006 4:03 am Post subject: Re: Password dialog for application? |
|
|
"Torsten Franz <FirstName_LastName at agilent dott >" <com> wrote in message
news:op.s432e1lkf7zh1z (AT) newsgroups (DOT) borland.com...
| Quote: | In this case the raw memory management new...delete caught my
eyes and I'd would have expected to see the smart pointer solution
|
I intentionally did not use a smart pointer for a very simple reason - by
doing so, the password form will remain sitting idle in memory for the
lifetime of the process. Whereas in my example, I am freeing the form from
memory as soon as it is no longer being used.
With that said, it is possible to use a smart pointer while still being able
to free the form when desired, by wrapping the smart pointer in its own
scope braces, ie:
#include <memory>
int WINAPI WinMain(HINSTANCE, HINSTANCE, LPSTR, int)
{
bool bOk = false;
// a new local scope is created here, and the smart
// pointer will be freed when the scope is done
{
std::auto_ptr<TPasswordForm> Form(new TPasswordForm(NULL));
if( mrOk == Form->ShowModal() )
bOk = true;
}
if( !bOk )
return 0;
// run the application ...
return 0;
}
Gambit |
|
| Back to top |
|
 |
Remy Lebeau (TeamB) Guest
|
Posted: Sat Feb 18, 2006 4:03 am Post subject: Re: Password dialog for application? |
|
|
"Alan Bellingham" <alanb (AT) episys (DOT) com> wrote in message
news:c3dcv1tec4glvt4o23tcu8ktvislgkebqa (AT) 4ax (DOT) com...
| Quote: | It's a potential error point.
|
The only error is if ShowModal() were to throw an exception that causes the
'delete' to be bypassed.
Gambit |
|
| Back to top |
|
 |
Torsten Franz Guest
|
Posted: Mon Feb 20, 2006 9:03 am Post subject: Re: Password dialog for application? |
|
|
| Quote: | I intentionally did not use a smart pointer for a very simple reason - by
doing so, the password form will remain sitting idle in memory for the
lifetime of the process. Whereas in my example, I am freeing the form
from memory as soon as it is no longer being used.
|
In this specific example your reasoning may be ok, but IMO it misleads the
novice reader to think that new...delete is the way to go also in all
other cases.
Torsten |
|
| Back to top |
|
 |
Torsten Franz Guest
|
Posted: Mon Feb 20, 2006 9:03 am Post subject: Re: Password dialog for application? |
|
|
| Quote: | What's wrong with new ... delete anyway?
To my mind it made Remy's explanation of the point in question
very clear and easy to understand. I would have found that the
use of the auto_ptr confused the issue, as everybody understands
new ... delete.
|
Using new...delete is not exactly wrong,
but it is manual memory (resource) management and this
is considered bad due to potential errors that could be
easily avoided by using automated constructs.
Torsten |
|
| 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
|
|