![]() |
Second Form and Thread
Hi , in my application i use a Second Form which is created on RunTime
Delphi-Quellcode:
in this Second Form i have 3 Buttons and 2 Labels
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;
Delphi-Quellcode:
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 ).
on main form button1 click event
MyNewForm.ShowModal; 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:
so how could i thread my SecondForm so that whenever i launch it it will not freeze and all their controls are still Visible .
.
. MyNewForm.label1.caption:={mainform.}label1.caption; MyNewForm.label2.caption:={mainform.}label2.caption; . . Regards. |
Re: Second Form and Thread
please is there any solution or suggestion on this Issue .
is it possible to create the Second Form threaded . |
Re: Second Form and Thread
Good morning.
A modal form has not to be closed with "TForm.Close". Zitat:
Delphi-Quellcode:
So you don't need to thread this modal form for that simple problem.
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; |
Re: Second Form and Thread
[quote="christian_r"]Good morning.
A modal form has not to be closed with "TForm.Close". Zitat:
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 |
Re: Second Form and Thread
Zitat:
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. ;) ) |
Re: Second Form and Thread
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:
Regards
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; |
Re: Second Form and Thread
Zitat:
Delphi-Quellcode:
What is that? :gruebel: You should post pseudo code that could be used and doesn't have to be corrected.
On MainForm Creat Event
On MainForm Destroy On TMainForm.Button1.Click 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:
unit2
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.
Delphi-Quellcode:
And again ...
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. Check your code! Stop to discuss! Post your relevant code! |
Alle Zeitangaben in WEZ +1. Es ist jetzt 17:06 Uhr. |
Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
LinkBacks Enabled by vBSEO © 2011, Crawlability, Inc.
Delphi-PRAXiS (c) 2002 - 2023 by Daniel R. Wolf, 2024-2025 by Thomas Breitkreuz