Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people, just like you, are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
Solved

Beginner - Pop up boxes

Posted on 2000-04-16
8
255 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
Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

 
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
 
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

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Print Graphic and Text to Epson TM-T88v 12 381
Delphi inherited method 6 76
Twebbrowser add css to the header 3 28
can i put an image from resource into image tag ? 6 27
Marketers need statistics and metrics like everybody else needs oxygen. In this article we explain how to enable marketing campaign statistics for Microsoft Exchange mail.
Marketing can be an uncomfortable undertaking, especially if your material is technology based. Luckily, we’ve compiled some simple and (relatively) painless tips to put an end to your trepidation and start your path to success.
Use Wufoo, an online form creation tool, to make powerful forms. Learn how to choose which pages of your form are visible to your users based on their inputs. The page rules feature provides you with an opportunity to create if:then statements for y…
Learn how to set-up PayPal payment integration in your Wufoo form. Allow your users to remit payment through PayPal upon completion of your online form. This is helpful for collecting membership payments, customer payments, donations, and more.

860 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