AGB  ·  Datenschutz  ·  Impressum  







Anmelden
Nützliche Links
Registrieren
Thema durchsuchen
Ansicht
Themen-Optionen

Second Form and Thread

Ein Thema von mohfa · begonnen am 4. Mai 2008 · letzter Beitrag vom 7. Mai 2008
Antwort Antwort
mohfa

Registriert seit: 11. Feb 2007
97 Beiträge
 
Delphi 7 Enterprise
 
#1

Second Form and Thread

  Alt 4. Mai 2008, 22:48
Hi , in my application i use a Second Form which is created on RunTime
Delphi-Quellcode:
var
MyNewForm:TSecondForm { this is the Second Form }
.
.
On the Main Form Creat Event
begin
if Not Assigned(MyNewForm) then
MyNewForm:=TSecondForm.create(Nil);
end;

// and release it on main Form Destroy event

MyNewForm.release;
in this Second Form i have 3 Buttons and 2 Labels

Delphi-Quellcode:
on main form button1 click event
MyNewForm.ShowModal;
when i launch this Second Form for the First Time every thing goes well , but when i launch it for the Second time it Freezes the Form is Shown but all other Controls are Hidden ( 3 BUTTONS + 2 LABELS ).
i thought it's because the Form is not safe Threaded.
but how could i thread it , the Values of the 2 labels are from the Main Form
Delphi-Quellcode:
.
.
MyNewForm.label1.caption:={mainform.}label1.caption;
MyNewForm.label2.caption:={mainform.}label2.caption;
.
.
so how could i thread my SecondForm so that whenever i launch it it will not freeze and all their controls are still Visible .


Regards.
  Mit Zitat antworten Zitat
mohfa

Registriert seit: 11. Feb 2007
97 Beiträge
 
Delphi 7 Enterprise
 
#2

Re: Second Form and Thread

  Alt 5. Mai 2008, 03:36
please is there any solution or suggestion on this Issue .

is it possible to create the Second Form threaded .
  Mit Zitat antworten Zitat
christian_r
(Gast)

n/a Beiträge
 
#3

Re: Second Form and Thread

  Alt 5. Mai 2008, 04:02
Good morning.

A modal form has not to be closed with "TForm.Close".

Zitat von Delphi Help:
To close a modal form, set its ModalResult property to a nonzero value.
As next here is the example of the same help topic. It explains, how to close the modal form in the right way.

Delphi-Quellcode:
procedure TMyDialogBox.OKButtonClick(Sender: TObject);

begin
  ModalResult := mrOK; // mrOK ...
end;

procedure TMyDialogBox.CancelButtonClick(Sender: TObject);
begin
  ModalResult := mrCancel; // ... and mrCancel are nonzero values
end;

// This code brings up the modal dialog from Form1 when a button is clicked. It causes a Beep if the OK button is clicked.

procedure TForm1.Button1Click(Sender: TObject);

begin
  if MyDialogBox1.ShowModal = mrOK then
    Beep;
end;
So you don't need to thread this modal form for that simple problem.
  Mit Zitat antworten Zitat
mohfa

Registriert seit: 11. Feb 2007
97 Beiträge
 
Delphi 7 Enterprise
 
#4

Re: Second Form and Thread

  Alt 5. Mai 2008, 04:21
[quote="christian_r"]Good morning.

A modal form has not to be closed with "TForm.Close".

Zitat von Delphi Help:
To close a modal form, set its ModalResult property to a nonzero value.
As next here is the example of the same help topic. It explains, how to close the modal form in the right way.

Hi christian_r that's not the problem , my problem is why when i Click for the Seconde Time on the Button to show the Second Form all Second Form controls are disappeared
  Mit Zitat antworten Zitat
christian_r
(Gast)

n/a Beiträge
 
#5

Re: Second Form and Thread

  Alt 5. Mai 2008, 09:26
Zitat von mohfa:
but when i launch it for the Second time it Freezes the Form is Shown but all other Controls are Hidden ( 3 BUTTONS + 2 LABELS ).
What does it means - "it freezes"? Can't you close it?

I think you should post more relevant code. The code you posted above is not the cause of the error in the manner described. (But this fact doesn't prevent you from fixing your kind of closing your modal form. )
  Mit Zitat antworten Zitat
mohfa

Registriert seit: 11. Feb 2007
97 Beiträge
 
Delphi 7 Enterprise
 
#6

Re: Second Form and Thread

  Alt 6. Mai 2008, 22:27
Hi christian_r , my problem is not in Closing the Second Form , my prolem is when i click 4 the Second Time to show the 2nd Form .
Here the 2nd Form is Shown but without Buttons or Labels . Only an empty Form .
Here is a Pseudo Code .
// the Second Form contains : 2 Buttons , 2 Labels .
Delphi-Quellcode:
On MainForm Creat Event
begin
if Not Assigned(SecondForm) then
SecondForm:=TSecondForm.Create(Nil); // here i Create the 2nd Form .
end;

On MainForm Destroy
begin
SecondForm.Release;// the 2nd Form is released
end;
(*
Here when i click on this Button1 the SecondForm is Shown
so 1st Click the Form is Shown Correctly with all its Controls.
the 2nd Click the Form is Shown but without any Controls on It .
Only an Empty Form
*)

On TMainForm.Button1.Click
begin
SecondForm.Label1.caption:={MainForm.}Label1.Caption;
SecondForm.Label2.caption:={MainForm}.Label2.Caption;
if SecondForm.ShowModal=MrOk then
// i have a Function to Execute
end;
Regards
  Mit Zitat antworten Zitat
christian_r
(Gast)

n/a Beiträge
 
#7

Re: Second Form and Thread

  Alt 7. Mai 2008, 08:22
Zitat von mohfa:
Here is a Pseudo Code.
I think you should post the relevant code you really used.

Delphi-Quellcode:
On MainForm Creat Event
On MainForm Destroy
On TMainForm.Button1.Click
What is that? You should post pseudo code that could be used and doesn't have to be corrected.

Here is a code that works. It's tested! It's the code, you posted as a pseudo code. And it doesn't cause any compiler errors and it doesn't cause your problem. It works fine!

unit1
Delphi-Quellcode:
unit Unit1;

interface

uses
  Windows, Classes, Controls, StdCtrls, Forms, Dialogs;

type
  TForm1 = class( TForm )
    Button1 : TButton;
    Label1 : TLabel;
    Label2 : TLabel;
    procedure FormCreate
              ( Sender : TObject );
    procedure Button1Click
              ( Sender : TObject );
  end;

var
  Form1 : TForm1;

implementation

uses Unit2;

{$R *.dfm}

procedure TForm1.FormCreate
          ( Sender : TObject );
begin
  if not Assigned( Form2 ) then
    Form2 := TForm2.Create( Nil );
end;

procedure TForm1.Button1Click
          ( Sender : TObject );
begin
  Form2.Label1.Caption := 'Caption Nr. 1';
  Form2.Label2.Caption := 'Caption Nr. 2';
  if Form2.ShowModal = mrOk then
    ShowMessage( 'Ok.' );
end;

end.
unit2
Delphi-Quellcode:
unit Unit2;

interface

uses
  Windows, Classes, Controls, StdCtrls, Forms, Dialogs;

type
  TForm2 = class( TForm )
    Label1 : TLabel;
    Label2 : TLabel;
    Button1 : TButton;
    Button2 : TButton;
    procedure Button1Click
              ( Sender : TObject );
  end;

var
  Form2 : TForm2;

implementation

{$R *.dfm}

procedure TForm2.Button1Click
          ( Sender : TObject );
begin
  Self.ModalResult := mrOk;
end;

end.
And again ...
Check your code!
Stop to discuss!
Post your relevant code!
  Mit Zitat antworten Zitat
Antwort Antwort


Forumregeln

Es ist dir nicht erlaubt, neue Themen zu verfassen.
Es ist dir nicht erlaubt, auf Beiträge zu antworten.
Es ist dir nicht erlaubt, Anhänge hochzuladen.
Es ist dir nicht erlaubt, deine Beiträge zu bearbeiten.

BB-Code ist an.
Smileys sind an.
[IMG] Code ist an.
HTML-Code ist aus.
Trackbacks are an
Pingbacks are an
Refbacks are aus

Gehe zu:

Impressum · AGB · Datenschutz · Nach oben
Alle Zeitangaben in WEZ +1. Es ist jetzt 08:17 Uhr.
Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
LinkBacks Enabled by vBSEO © 2011, Crawlability, Inc.
Delphi-PRAXiS (c) 2002 - 2023 by Daniel R. Wolf, 2024 by Thomas Breitkreuz