Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Wanet Telecoms Ltd on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Cancel Form Opening 1

Status
Not open for further replies.

lespaul

Programmer
Feb 4, 2002
7,083
US
If I have a process in the OnShow procedure and want to exit and not show the form, how can I accomplish this? For example, I have a form that is used to Record Courtroom Use, however, if someone tries to perform that function and there are no Trials currently in progress, how can I abort the showing of the form?

thanks!

leslie
 
You should move the check to initiate the display to somewhere before the OnShow event. The code should be more general, like a function AreTrialsInProgress(eCourtroom: enCourtrooms) : boolean; and call that in the OnClick event of the button that should open the form.

HTH
TonHu
 
that's kinda what I'm doing now, but wanted to see if there was another way.

thanks!
leslie
 
you just close it after the check,
it still pops up if the system is slow, but will immediately close.
 
agree with schu, yes its 'messy' but I have a couple of 'check somthing' at startup type things that do just that.
I have also noticed several 'lots of money' type apps that 'flash' a startup window at you, before opening properly, not quite the same thing, but with todays fast machines.



Steve: Delphi a feersum engin indeed.
 
Thanks for the additional confirmation!

leslie
 

Some questions:

1. Is this the main form?
2. Is this a modal dialog or modeless?
3. Is Delphi creating the form (auto-create) or are you?
4. Are you using an MDI architecture?

 
1. No it is not the main form.

2. It is not currently a modal form, but that is certainly possible to do.

3. I am creating the form.

4. No, no MDI.

Thanks!

leslie
 

Using a modal dialog is simplest. The way I do it is to make a global function to encapsulate all of the necessary code. This allows the calling unit to work simply with one line of code.

For example, the main routine might have a line of code like this:
Code:
  if MyCustomDialog( SomeInputParm, SomeOutputParm )= mrOk then
    GoNextStep( SomeOutputParm );

And the second unit would define the global function and implement it something like this:
Code:
interface

  function MyCustomDialog(AInput:string; var AOutput:string ):TModalResult;

type
  TModalResult = class(TForm)
  private
    FInput:string;
    FOutput:string;
    :
    :
  public
    :
    :
  end;

implementation

  function MyCustomDialog(AInput:string; var AOutput:string ):TModalResult;
  begin
    if DataExist(AInput) then
      with TMyCustomDialog.Create do
        begin
          FInput := AInput;
          ShowModal;
          AOutput := FOutput;
          Result := ModalResult;  // mrOk or mrCancel
          Free;
        end
    else
      Result := mrNo;
  end;

The OnShow event would use the value in FInput to initialize the form.

If it is time-consuming to retrieve the data for the form, you could use one of the techniques available that can show the form first, before fetching data. One way is to use a timer and populate the dialogwith the OnTimer event. Another way is to define your own message and post it to the dialog, then use a message handler event to populate the dialog.
 
That's pretty cool, I'll give it a try!

Thanks,
Leslie
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top