Re: Form problem

From: MiguŽl (m_b_at_pandora.be)
Date: 12/24/03


Date: Wed, 24 Dec 2003 17:06:25 +0100

Kurt

Can you tell me where I have to put that code ?

for the frmCases I have already this code

--
procedure TfrmCases.FormCreate(Sender: TObject);
begin
  frmCases.Position := poScreencenter;
  edit1.Visible := True;
  query1.SQL.Text := 'select count(*) as aantal from unit';
  query1.Open;
  edit1.Text := query1.fieldbyname('aantal').AsString;
end;
procedure TfrmCases.FormActivate(Sender: TObject);
begin
   if edit1.Text = '0' then
      begin
      form1.Height := 467;
      form1.Width := 530;
      form1.Left := 250;
      form1.Top := 145;
      frmUnit.ShowModal;
      end
end;
---
and for the frmUnit I have this code :
--
procedure TfrmUnit.bbtSaveClick(Sender: TObject);
begin
  if (Trim(edtName.Text) = '') or (Trim(edtStreet.Text) = '') or
      (Trim(edtPost.Text) = '') or (Trim(edtCity.Text) = '') or
      (Trim(edtPhone.Text) = '') or (Trim(edtFax.Text) = '') or
      (Trim(edtMail.Text) = '') then
      begin
      Application.MessageBox('All fields must be filled in.', 'Error define'
+
                            ' unit', MB_ICONINFORMATION + MB_OK);
      if (Trim(edtName.Text ) = '') then
          edtName.SetFocus
       else if (Trim(edtStreet.Text) = '') then
                edtStreet.SetFocus
        else if (Trim(edtPost.Text) = '') then
                 edtPost.SetFocus
         else if (Trim(edtCity.Text) = '') then
                  edtCity.SetFocus
          else if (Trim(edtPhone.Text) = '') then
                   edtPhone.SetFocus
           else if (Trim(edtFax.Text) = '') then
                    edtFax.SetFocus
            else if (Trim(edtMail.Text) = '') then
                     edtMail.SetFocus
      end
    else
       begin
       query1.SQL.Text := 'insert into unit values (:Name, :Street, :Post,'
+
                          ' :City, :Phone, :Fax, :Mail)';
       query1.ParamByName('Name').AsString := edtName.Text;
       query1.ParamByName('Street').AsString := edtStreet.Text;
       query1.ParamByName('Post').AsString := edtPost.Text;
       query1.ParamByName('City').AsString := edtCity.Text;
       query1.ParamByName('Phone').AsString := edtPhone.Text;
       query1.ParamByName('Fax').AsString := edtFax.Text;
       query1.ParamByName('Mail').AsString := edtMail.Text;
       query1.ExecSQL;
       Application.MessageBox('Unit defined' + #13#10 + 'Program will be' +
                              ' started', 'Define unit', MB_ICONINFORMATION
+
                              MB_OK);
       frmUnit.Hide;
       end
end;
--
For Brad
This code is used either in FormClose either in FormCloseQuery
--
procedure TfrmUnit.FormCloseQuery(Sender: TObject; var CanClose: Boolean);
begin
  Application.MessageBox('Unit not defined.' + #13#10#13#10 +
                         'You must define unit before you can use the
program.' +
                         #13#10 + 'Next time you run the program you will' +
                         ' have to define your unit.', 'Ecase - Close',
                         MB_ICONWARNING + MB_OK);
  Application.Terminate;
end;
--
"Kurt Barthelmess (TeamB)" <kbarthelmess@compuserve.com> schreef in bericht
news:3fe8bca6.20955021@newsgroups.borland.com...
> "MiguŽl" <d-force@pandora.be> wrote via email:
>
> First, please do not send your response via email. Followup here on
> the newsgroups.
>
> >I tried with the frmUnit.ShowModal and it works.
>
> Good.
>
> >I have an other problem :
> >I wrote a statement for either the frmUnit.Close either
frmUnit.CloseQuery
> >that when a person clicks on the "X" in the bordericons the program has
to
> >end  (application.Terminate). So now when I say frmUnit.Hide the program
> >stops.
> >What do I have to do to avoid that because I want to keep the statements.
>
> When the user clicks on the Close ("X") button , the form will close
> and be hidden automatically. It will also set its ModalResult property
> to mrCancel and that value will be returned by by the ShowModal
> function. So there is no reason to call Application.Terminate at that
> point; let frmCases do that:
>
>   case frmUnit.ShowModal of
> mrOK:
>     begin
> // the form closed with an "OK"
>     end;
> mrCancel:
>     begin
> // the form closed by a Cancel button or by clicking on the "X"
>     end;
>   end;
>
> Good luck.
>
> Kurt
>