Autor Beitrag
ardely
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 66



BeitragVerfasst: Mi 14.08.13 15:51 
Hallo,
Ich habe eine dynamische Form und ich möchte gern nach 8 Sekunden die Form automatisch schließen!
ausblenden volle Höhe Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
30:
31:
32:
33:
34:
35:
36:
37:
38:
39:
..
type
 TFormDy = class(TForm)
 private

 published
  procedure OpFormClose(Sender: TObject; var Action: TCloseAction);
  procedure OpOnShow(Sender: TObject);
  procedure OpTimer1Timer(Sender: TObject);
  procedure ShowFormDy(sTxt: string);
 end;
 
var
 FormDy: TFormDy;
 Count: integer;
 Timer1: TTimer;
 

implementation
...
...


procedure TFormDy.ShowFormDyn(sTxt: string);
var
 Fdy: TForm;
begin
 
 Fdy := TForm.Create(nil); 
 try
 .. 
  Fdy.OnClose := OpFormClose; 
  Fdy.OnShow := OpOnShow;
  ..
  Fdy.ShowModal;
 finally
  Fdy.Free;
 end;
end;


Ich habe versucht mit einem timer aber ich bekomme einen
error: raised exception class EAccessViolation , was soll ich Verbessern?

ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
procedure TFormDy.OpOnShow(Sender: TObject);
begin
 Count := 0;
 Timer1 := TTimer.Create(nil);
 Timer1.OnTimer := OpTimer1Timer;
 Timer1.Interval := 1000;
 Timer1.Enabled := True;
end;
 
procedure TFormDy.OpTimer1Timer(Sender: TObject);
begin
 Inc(Count);
// if  Count > 8 then Fdy.close; // <-- Fehler 
if  Count > 8 then TForm(Sender).Close; // <-- Fehler 
end;


Ich bedanke mich herzlich für Ihre Unterstützung.
WasWeißDennIch
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 653
Erhaltene Danke: 160



BeitragVerfasst: Mi 14.08.13 16:38 
Wieso erzeugst Du eine Instanz von TForm, wäre da die Ableitung TDynForm nicht geeigneter? Da packst Du dann einfach einen Timer mit Intervall 8000 drauf und schließt in dessen Timer-Handler das Formular wieder.

[edit] So, ich hab das mal schnell unter Delphi 7 gebastelt. DynForm-Unit (Timer.Intervall 8000, Timer.Enabled auf true):
ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
unit uDynForm;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, ExtCtrls;

type
  TDynForm = class(TForm)
    Timer1: TTimer;
    procedure Timer1Timer(Sender: TObject);
  private
    { Private-Deklarationen }
  public
    { Public-Deklarationen }
  end;

implementation

{$R *.dfm}

procedure TDynForm.Timer1Timer(Sender: TObject);
begin
  Close;
end;

end.


Und hier das Anzeigen:
ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
procedure TForm1.Button1Click(Sender: TObject);
var
  DynForm: TDynForm;
begin
  DynForm := TDynForm.Create(nil);
  try
    DynForm.ShowModal;
  finally
    DynForm.Free;
  end;
end;
[/edit]

Für diesen Beitrag haben gedankt: ardely
ardely Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 66



BeitragVerfasst: Do 15.08.13 11:49 
Sehr vielen Dank für dein Beispiel der mir auf den Weg gebracht hat mein Problem zu lösen.