• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 174
  • Last Modified:

Autoclose form.

Hello, I have this issue. A form that runs only a progress bar (until now, just only a for loop to test it), that is going to do a sincronization task. The form is declared with these properties values: BorderStyle = bsDialog or bsToolWindow, Position = poDesktopCenter, BorderIcons = []. The rest remains default.
This form is execute with showmodal in the ButtonCloseClick event of the main form of the application.

The only code it has in is this:
procedure TfrmSincronizationTask.FormActivate(Sender: TObject);
var i: integer;
begin
  for i := 0 to pgSincronization.Max do
    pgSincronization.StepIt;
  ModalResult := mrOk;
end;

The form is called in this way:
      frmSincronizationTask := TfrmSincronizationTask.Create(Application);
      frmSincronizationTask.ShowModal;
      frmSincronizationTask.Free;
      frmSincronizationTask := nil;

What i need is the form closing automatically when the task is finished, but it don't.

I will appreciate some help
Thanks you in advance,
0
spk2000ar
Asked:
spk2000ar
1 Solution
 
spk2000arAuthor Commented:
I consider the question easy, but urgent, so the points...
0
 
_Katka_Commented:
Hi, try to move your code into FormShow instead of FormActivate
I guess it's not possible to apply ModalResult in Activation event.

regards,
Kate
0
 
esoftbgCommented:
type
  TfrmSincronizationTask = class(TForm)
      pgSincronization: TProgressBar;
    TimerSincronization: TTimer;
      procedure FormActivate(Sender: TObject);
      procedure TimerSincronizationTimer(Sender: TObject);
    private
    { Private declarations }
    public
    { Public declarations }
  end;

var
  frmSincronizationTask: TfrmSincronizationTask;

implementation

{$R *.dfm}

procedure TfrmSincronizationTask.FormActivate(Sender: TObject);
var
  I:      Integer;
begin
  for I := 0 to pgSincronization.Max do
    pgSincronization.StepIt;
  TimerSincronization.Enabled := True;
end;

procedure TfrmSincronizationTask.TimerSincronizationTimer(Sender: TObject);
begin
  Close;
  ModalResult := mrOk
end;

end.
0
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 
esoftbgCommented:
object frmSincronizationTask: TfrmSincronizationTask
  Left = 256
  Top = 128
  BorderIcons = []
  BorderStyle = bsToolWindow
  Caption = 'Sincronization Task'
  ClientHeight = 158
  ClientWidth = 504
  Color = clBtnFace
  Font.Charset = DEFAULT_CHARSET
  Font.Color = clWindowText
  Font.Height = -11
  Font.Name = 'MS Sans Serif'
  Font.Style = []
  OldCreateOrder = False
  Position = poDesktopCenter
  OnActivate = FormActivate
  PixelsPerInch = 96
  TextHeight = 13
  object pgSincronization: TProgressBar
    Left = 8
    Top = 64
    Width = 480
    Height = 17
    Max = 10000
    TabOrder = 0
  end
  object TimerSincronization: TTimer
    Enabled = False
    Interval = 100
    OnTimer = TimerSincronizationTimer
    Left = 34
    Top = 18
  end
end
0
 
BlackTigerXCommented:
if you call it with ShowModal it will stop any other processing in the main form, you might consider something like this:

frmSincronizationTask := TfrmSincronizationTask.Create(Application);
try    
  frmSincronizationTask.Show;
  doYourProcessingHere();
finally
  frmSincronizationTask.Free;
  frmSincronizationTask := nil;
end;
0
 
spk2000arAuthor Commented:
_Katka_: it does not work.
BlackTigerX: i do not need to do any processing in the main form, only in the new form. It might work but is better for my porpouse that the code of the sincronization task keeps in the sincronization form, separeted from the original code.
esoftbg: i am looking for a more elegant solution (i tried something like that with an invisible button and do not work), but what you say, works. So i will give you the points for the efforts on answering the question. What is more, elegant or not, is what i am going to use... THANKS!!!
0
 
esoftbgCommented:
spk2000ar, you are welcome !
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Tackle projects and never again get stuck behind a technical roadblock.
Join Now