Link to home
Start Free TrialLog in
Avatar of frize
frizeFlag for Algeria

asked on

Form Auto-Close with Timer

Hello .

Please Can someone correct me this Project :
It uses 2 Forms
MainForm and Form2

and Tfindfile Components and a Timer

so i want the Form2 will AutoClose after some Seconds

please see the Project for details .

TFindFile : http://www.delphiarea.com/products/findfile/findfile.zip

* How could i assign the ' Don't Show this Again

Thank you All .
program Project1;
 
uses
  Forms,
  Unit1 in 'Unit1.pas' {Form1},
  Unit2 in 'Unit2.pas' {Form2};
 
{$R *.res}
 
begin
  Application.Initialize;
  Application.CreateForm(TForm1, Form1);
  If Form2=Nil then
  Form2:=TForm2.Create(Application);
  Application.Run;
end.
------------- Unit1
unit Unit1;
 
interface
 
uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, StdCtrls, FindFile;
 
type
  TForm1 = class(TForm)
    df: TFindFile;
    CheckBox1: TCheckBox;
    Button1: TButton;
    Button2: TButton;
    procedure Button1Click(Sender: TObject);
    procedure Button2Click(Sender: TObject);
    procedure dfFileMatch(Sender: TObject; const Folder: String;
      const FileInfo: TSearchRec);
  private
    { Private declarations }
  public
    { Public declarations }
  end;
 
var
  Form1: TForm1;
 
implementation
 
uses Unit2;
 
{$R *.dfm}
 
procedure TForm1.Button1Click(Sender: TObject);
begin
df.Execute;// TFindFile
end;
 
procedure TForm1.Button2Click(Sender: TObject);
begin
if df.Busy then
df.Abort;
end;
Function Showp( Dir,Fn:String):Boolean;
begin
Result:=False;
If  Result then
if Form2=Nil then
form2:=tform2.create(Application);
Form2.dir.Caption:=Dir;
Form2.fl.Caption:=Fn;
Form2.ShowAgain;
form2.showmodal();
//form2.free;
 // How to assign the Don't Show Again
// Form1.checked=Not(Form2.CheckBox1.checked);
 
end;
procedure TForm1.dfFileMatch(Sender: TObject; const Folder: String;
  const FileInfo: TSearchRec);
begin
IF df.Threaded then begin
if CheckBox1.Checked then
Showp(Folder,FileInfo.Name);
end;
end;
end.
----------- unit2
unit Unit2;
 
interface
 
uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, StdCtrls, ExtCtrls;
 
type
  TForm2 = class(TForm)
    Button1: TButton;
    Timer1: TTimer;
    Label1: TLabel;
    Label2: TLabel;
    dir: TLabel;
    fl: TLabel;
    Label3: TLabel;
    Label4: TLabel;
    CheckBox1: TCheckBox;
    procedure Timer1Timer(Sender: TObject);
    procedure FormCreate(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
   procedure  ShowAgain;
  end;
 
var
  Form2: TForm2;
  Count:Integer;
 
implementation
 
{$R *.dfm}
 
procedure TForm2.Timer1Timer(Sender: TObject);
begin
Inc(Count,1);
Label3.Caption:=IntToStr(Count);
If Count=10 then begin
Form2.ModalResult:=MrOk;
Count:=0;
Timer1.Enabled:=False;
end;
end;
 
procedure TForm2.FormCreate(Sender: TObject);
begin
Count:=0;
Timer1.Interval:=100;
Timer1.Enabled:=true;
end;
 
procedure TForm2.ShowAgain;
begin
Timer1.Enabled:=true;
end;
 
end.
-----------
object Form1: TForm1
  Left = 202
  Top = 105
  Width = 783
  Height = 540
  Caption = 'Form1'
  Color = clBtnFace
  Font.Charset = DEFAULT_CHARSET
  Font.Color = clWindowText
  Font.Height = -11
  Font.Name = 'Tahoma'
  Font.Style = []
  OldCreateOrder = False
  PixelsPerInch = 96
  TextHeight = 13
  object CheckBox1: TCheckBox
    Left = 80
    Top = 136
    Width = 273
    Height = 17
    Caption = 'Show Popup form'
    TabOrder = 0
  end
  object Button1: TButton
    Left = 88
    Top = 16
    Width = 75
    Height = 25
    Caption = 'Start'
    TabOrder = 1
    OnClick = Button1Click
  end
  object Button2: TButton
    Left = 176
    Top = 16
    Width = 75
    Height = 25
    Caption = 'Stop'
    TabOrder = 2
    OnClick = Button2Click
  end
  object df: TFindFile
    Criteria.Files.FileName = '*.zip'
    Criteria.Files.Location = 'C:\'
    Criteria.Files.Included.Strings = (
      '*.dll')
    Threaded = True
    OnFileMatch = dfFileMatch
    Left = 120
    Top = 56
  end
end
-------------
object Form2: TForm2
  Left = 350
  Top = 118
  BorderStyle = bsDialog
  Caption = 'Form2'
  ClientHeight = 311
  ClientWidth = 395
  Color = clBtnFace
  Font.Charset = DEFAULT_CHARSET
  Font.Color = clWindowText
  Font.Height = -11
  Font.Name = 'Tahoma'
  Font.Style = []
  OldCreateOrder = False
  OnCreate = FormCreate
  PixelsPerInch = 96
  TextHeight = 13
  object Label1: TLabel
    Left = 0
    Top = 32
    Width = 29
    Height = 13
    Caption = 'Path :'
  end
  object Label2: TLabel
    Left = 0
    Top = 64
    Width = 23
    Height = 13
    Caption = 'File :'
  end
  object dir: TLabel
    Left = 32
    Top = 32
    Width = 12
    Height = 13
    Caption = 'dir'
  end
  object fl: TLabel
    Left = 32
    Top = 64
    Width = 6
    Height = 13
    Caption = 'fl'
  end
  object Label3: TLabel
    Left = 72
    Top = 152
    Width = 31
    Height = 13
    Caption = 'Label3'
  end
  object Label4: TLabel
    Left = 0
    Top = 152
    Width = 70
    Height = 13
    Caption = 'AutoClose in : '
  end
  object Button1: TButton
    Left = 168
    Top = 248
    Width = 75
    Height = 25
    Caption = 'Button1'
    ModalResult = 1
    TabOrder = 0
  end
  object CheckBox1: TCheckBox
    Left = 8
    Top = 192
    Width = 249
    Height = 17
    Caption = 'Don''t Show Me this Window Again '
    TabOrder = 1
  end
  object Timer1: TTimer
    Enabled = False
    OnTimer = Timer1Timer
    Left = 32
    Top = 232
  end
end
--------------

Open in new window

Avatar of Geert G
Geert G
Flag of Belgium image

you have some bugs in your code which make it difficult to follow what you want to do.

you want to show a Form2 and then close it after a while or after something has happened ?

what is you want to do exactly ?
without using code
ASKER CERTIFIED SOLUTION
Avatar of bernani
bernani
Flag of Belgium image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial