Solved

Beginner - Pop up boxes

Posted on 2000-04-16
8
253 Views
Last Modified: 2013-11-28
I'm learning Delphi 3 as part of a college course. My question is I have an exit button on my form and want to have a "Are you sure you want to Quit" dialog box pop up when the button is clicked, and if Yes is chosen the project closes but if no is clicked then you are returned to the original form. How do I do this? Also - on the same theme. I have a Clear button on my form. When the button is clicked the values or text entered in edit boxes 1 to 4 are cleared. How do I get a dialog box to pop up "Are you sure?" and if yes is chosen then the dialog box closes and the edit boxes are cleared or if no is chosen then the dialog box closes and you are returned to the original form?

Many thanks

Nick

PS. Only just started learning Delphi so I'd appreciate "an idiots guide" for an answer. :o)
0
Comment
Question by:NickRackham
  • 4
  • 4
8 Comments
 
LVL 7

Expert Comment

by:Motaz
ID: 2720244
Exit button:

write this code in Button's OnClick event:

if MessageDlg('Are you sure', mtConfirmation, [mbYes, mbNo], 0) = idYes then Close;

Motaz
0
 
LVL 7

Expert Comment

by:Motaz
ID: 2720246
Clear button:

Write:

if MessageDlg('Are you sure', mtConfirmation, [mbYes, mbNo], 0) = idYes then
begin
  Edit1.Clear;
  Edit2.Clear;
  Edit3.Clear;
  Edit4.Clear;
end;

Good luck

I also have an Electronic Book for learning Delphi
www.gocities.com/motaz1

By the way in which university are you now and in which year.
Motaz
0
 
LVL 4

Author Comment

by:NickRackham
ID: 2720255
Motaz,

Thanks for the quick response. The exit code works fine but the clear button ????

If No ischosen then edit 2 - 4 are cleared but edit 1 isn't. If Yes is chosen then Edit 1 - 4 are cleared. Very strange. Can you help further?

Nick

PS I'm at Suffolk College doing an HNC in Computing - First Year. I'll have a look at your web site later when I've got more time. :o)
0
 
LVL 7

Accepted Solution

by:
Motaz earned 100 total points
ID: 2720267
Make sure of begin end where did you put it, any how I'll post it again:

begin
  if MessageDlg('Are you sure', mtConfirmation, [mbYes, mbNo], 0) = idYes then
  begin
    Edit1.Clear;
    Edit2.Clear;
    Edit3.Clear;
    Edit4.Clear;
  end;
end;

MOtaz
0
Zoho SalesIQ

Hassle-free live chat software re-imagined for business growth. 2 users, always free.

 
LVL 4

Author Comment

by:NickRackham
ID: 2720299
Motaz,

Excellent - Many thanks.

No doubt they'll be more questions posted on EE before I've finished :o)

Nick
0
 
LVL 4

Author Comment

by:NickRackham
ID: 2720301
Motaz, Just one more thing - How do I link the Close button on my form to bring up the same dialog box as when the Exit button is clicked. I've just noticed that you can close the form with out an "Are you sure" dialog box appearing if you close the form with the close  X  button on the top right of the form.

Nick
0
 
LVL 4

Author Comment

by:NickRackham
ID: 2720307
Motaz, Don't worry, I've found it

procedure TForm1.FormClose(Sender: TObject; var Action: TCloseAction);

begin
  if MessageDlg('Close application ?', mtConfirmation,
    [mbYes, mbNo], 0) = mrYes then
    Action := caFree
  else
    Action := caNone;
end;

Many thanks

Nick

PS - Perhaps I should have looked at the Help first!!
0
 
LVL 7

Expert Comment

by:Motaz
ID: 2720342
Good luck
0

Featured Post

Zoho SalesIQ

Hassle-free live chat software re-imagined for business growth. 2 users, always free.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Read about how to approach blogging and about ways to do it right. Stand out from the crowd and let your knowledge be consumed by a large audience. This article aims to explain how your blog should look like,  the most important things to do while b…
Read about why website design really matters in today's demanding market.
An overview of how to create reports in Adobe Analytics (formerly Omniture Site Catalyst) using pageNames, events, eVars and props. This video will show you how to install the Omniture Debugger tool so can see (and test) what is being passed int…
Use Wufoo, an online form creation tool, to make powerful forms. Learn how to selectively show certain fields based on user input using rules to gather relevant information and data from your forms. The rules feature provides you with an opportunity…

948 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

22 Experts available now in Live!

Get 1:1 Help Now