?
Solved

Destroing a form from its button. All created from code.

Posted on 2006-05-04
3
Medium Priority
?
236 Views
Last Modified: 2010-04-05
I have this:

var
  DisplayForm: TForm;
  CloseBtn: TButton;
begin
  DisplayForm := TForm.Create(nil);

  DisplayForm.Parent := nil;
  DisplayForm.Width := 500;
  DisplayForm.Height := 400;
  DisplayForm.Position := poDesktopCenter;
  DisplayForm.BorderStyle := bsSingle;
  DisplayForm.BorderIcons := [biSystemMenu];
  DisplayForm.Color := DisplayMessage.background_color;

  CloseBtn := TButton.Create(DisplayForm);
  CloseBtn.Parent := DisplayForm;
  CloseBtn.Left := 405;
  CloseBtn.Top := 330;
  CloseBtn.Caption := 'Close';

  CloseBtn.Visible := True;

  DisplayForm.Visible := True;
  CloseBtn.OnClick := AA;
end;

and in AA I have:

procedure TReminder.AA(Sender: TObject);
begin
  TForm(Sender).Parent.Destroy;
end;


What I`m trying to do is to destroy the form when I push the button! Can anyone help me ASAP ?

Thanks,
0
Comment
Question by:crystyan
  • 2
3 Comments
 
LVL 27

Expert Comment

by:kretzschmar
ID: 16607503
replace
 TForm(Sender).Parent.Destroy;
with
 TForm(Sender).Parent.Release;

meikl ;-)
0
 
LVL 27

Accepted Solution

by:
kretzschmar earned 1000 total points
ID: 16607566
hmm would not really work so i guess

try this
var f : TForm;

if (sender is TWinControl) then
  if (TWinControl(sender).parent is Tform) then
  begin
    f :=  TWinControl(sender).parent as TForm;
    f.release;
  end;

on the other hand you could implement an onClose event of your TForm
with content

  action := caFree;

your buttonCode looks then like

if (sender is TWinControl) then
  if (TWinControl(sender).parent is Tform) then
  begin
    f :=  TWinControl(sender).parent as TForm;
    f.close;
  end;

 meikl ;-)
0
 

Author Comment

by:crystyan
ID: 16608479
It works ace !!!
Thanks!
0

Featured Post

Hire Technology Freelancers with Gigs

Work with freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely, and get projects done right.

Question has a verified solution.

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

Introduction The parallel port is a very commonly known port, it was widely used to connect a printer to the PC, if you look at the back of your computer, for those who don't have newer computers, there will be a port with 25 pins and a small print…
In my programming career I have only very rarely run into situations where operator overloading would be of any use in my work.  Normally those situations involved math with either overly large numbers (hundreds of thousands of digits or accuracy re…
Is your OST file inaccessible, Need to transfer OST file from one computer to another? Want to convert OST file to PST? If the answer to any of the above question is yes, then look no further. With the help of Stellar OST to PST Converter, you can e…
With just a little bit of  SQL and VBA, many doors open to cool things like synchronize a list box to display data relevant to other information on a form.  If you have never written code or looked at an SQL statement before, no problem! ...  give i…
Suggested Courses

862 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