Solved

Beginner - Pop up boxes

Posted on 2000-04-16
8
257 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
[X]
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
  • 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
Online Training Solution

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action. Forget about retraining and skyrocket knowledge retention rates.

 
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

[Webinar] Code, Load, and Grow

Managing multiple websites, servers, applications, and security on a daily basis? Join us for a webinar on May 25th to learn how to simplify administration and management of virtual hosts for IT admins, create a secure environment, and deploy code more effectively and frequently.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Base1 Encode/Decode 3 100
Graphics32 under Delphi 10.1 Berlin 2 187
can i put an image from resource into image tag ? 6 42
Formating a integer number to float 2 9
Every business owner understands the significance of online customer reviews and the impact it can have on sales and revenues. With technology advancing at such a rapid pace, getting online reviews has never been easier, especially when many regions…
CTAs encourage people to do something specific to show interest in your company, product or service. Keep reading to learn why CTAs should always be thought of as extremely important, albeit small, sections of websites.
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…
Learn how to set-up custom confirmation messages to users who complete your Wufoo form. Include inputs from fields in your form, webpage redirects, and more with Wufoo’s confirmation options.

751 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