Solved

Beginner - Pop up boxes

Posted on 2000-04-16
8
252 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
How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

 
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

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Read about how to choose the best possible content marketing agency to suit your needs. Content marketing has become an integral part of running a successful tech business, so it is wise to be informed.
Read about the 3 stages of the buyer's journey: awareness, consideration, and decision.
Viewers will get an overview of the benefits and risks of using Bitcoin to accept payments. What Bitcoin is: Legality: Risks: Benefits: Which businesses are best suited?: Other things you should know: How to get started:
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…

706 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

16 Experts available now in Live!

Get 1:1 Help Now