BorlandTalk.com Forum Index BorlandTalk.com
Borland discussion newsgroups
 
Archives   FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

Password dialog for application?

 
Post new topic   Reply to topic    BorlandTalk.com Forum Index -> C++ Builder (Language C++)
View previous topic :: View next topic  
Author Message
dzeidzei
Guest





PostPosted: Wed Feb 15, 2006 8:03 pm    Post subject: Password dialog for application? Reply with 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!

-dzeidzei
Back to top
Liz Albin
Guest





PostPosted: Wed Feb 15, 2006 8:03 pm    Post subject: Re: Password dialog for application? Reply with quote



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





PostPosted: Wed Feb 15, 2006 10:03 pm    Post subject: Re: Password dialog for application? Reply with quote



"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





PostPosted: Thu Feb 16, 2006 7:03 pm    Post subject: Re: Password dialog for application? Reply with quote

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





PostPosted: Fri Feb 17, 2006 10:03 am    Post subject: Re: Password dialog for application? Reply with quote

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





PostPosted: Fri Feb 17, 2006 8:03 pm    Post subject: Re: Password dialog for application? Reply with 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.

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





PostPosted: Fri Feb 17, 2006 9:03 pm    Post subject: Re: Password dialog for application? Reply with quote

"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





PostPosted: Sat Feb 18, 2006 4:03 am    Post subject: Re: Password dialog for application? Reply with quote

"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





PostPosted: Sat Feb 18, 2006 4:03 am    Post subject: Re: Password dialog for application? Reply with quote

"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





PostPosted: Mon Feb 20, 2006 9:03 am    Post subject: Re: Password dialog for application? Reply with quote

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





PostPosted: Mon Feb 20, 2006 9:03 am    Post subject: Re: Password dialog for application? Reply with quote

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
Display posts from previous:   
Post new topic   Reply to topic    BorlandTalk.com Forum Index -> C++ Builder (Language C++) All times are GMT
Page 1 of 1

 
Jump to:  
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


Powered by phpBB © 2001, 2006 phpBB Group
SEO toolkit © 2004-2006 webmedic.