| |

VerySource

 Forgot password?
 Register
Search
View: 1041|Reply: 5

Why doesn't this program launch two windows at the same time?

[Copy link]

2

Threads

4

Posts

5.00

Credits

Newbie

Rank: 1

Credits
5.00

 China

Post time: 2020-2-17 19:30:01
| Show all posts |Read mode
The UNITS CHANGEOWNER code is as follows:
program CHANGEOWNER;

uses
  Forms,
  YUANLAI in 'YUANLAI.pas' {Form1},
  HOULAI in 'HOULAI.pas' {Form2};

{$ R * .res}

begin
  Application.Initialize;
  Application.CreateForm (TForm1, Form1);
  Application.CreateForm (TForm2, Form2);
  Application.Run;
end.

The UNITS YUANLAI code is as follows:
unit YUANLAI;

interface

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

type
  TForm1 = class (TForm)
    ButtonCHG: TButton;
    Button1: TButton;
    ButtonLIST: TButton;
    ListBox1: TListBox;
    procedure Button1Click (Sender: TObject);
    procedure ButtonLISTClick (Sender: TObject);
    procedure ButtonCHGClick (Sender: TObject);
  private
    {Public declarations}
  public
    {Public declarations}
  end;

var
  Form1: TForm1;

implementation

USES HOULAI;

{$ R * .dfm}

procedure TForm1.Button1Click (Sender: TObject);
begin
    ShowMessage ('My owner is' + ((Sender as TButton) .Owner as TForm) .Name);
end;

procedure TForm1.ButtonLISTClick (Sender: TObject);
var i: Integer;
begin
self.ListBox1.Items.Clear;
for i: = 0 to Componentcount-1do
 begin
     self.ListBox1.Items.Add (Components [i] .Name);
 end;
end;

procedure change (com, newowner: TComponent);
begin
     com.Owner.RemoveComponent (com);
     newowner.InsertComponent (com);
end;

procedure TForm1.ButtonCHGClick (Sender: TObject);
begin
if Assigned (self.Button1)
  then
     self.Button1.Parent: = Form2;
     change (Button1, Form2);
end;


end.

The UNINTS HOULAI code is as follows:
unit HOULAI;

interface

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

type
  TForm2 = class (TForm)
    ButtonLIST: TButton;
    ListBox1: TListBox;
    procedure ButtonLISTClick (Sender: TObject);
  private
    {Private declarations}
  public
    {Public declarations}
  end;

var
  Form2: TForm2;

implementation

{$ R * .dfm}

procedure TForm2.ButtonLISTClick (Sender: TObject);

    var i: Integer;
begin
self.ListBox1.Items.Clear;
for i: = 0 to Componentcount-1do
 begin
     self.ListBox1.Items.Add (Components [i] .Name);
 end;
end;

end.


thanks, thanks!
Reply

Use magic Report

0

Threads

17

Posts

16.00

Credits

Newbie

Rank: 1

Credits
16.00

 China

Post time: 2020-4-21 11:15:01
| Show all posts
begin
  Application.Initialize;
  Application.CreateForm (TForm1, Form1);
  Application.CreateForm (TForm2, Form2);
  Form2.show;
  Application.Run;
end.
Reply

Use magic Report

0

Threads

1

Posts

2.00

Credits

Newbie

Rank: 1

Credits
2.00

 China

Post time: 2020-5-1 18:15:01
| Show all posts
After the application creates the corresponding form, the first created form (main form) is displayed by default. You can display Form2 likelazying, or open Form2 when the main form is displayed
Reply

Use magic Report

0

Threads

53

Posts

29.00

Credits

Newbie

Rank: 1

Credits
29.00

 China

Post time: 2020-5-2 09:30:01
| Show all posts
Yes, there are many ways, upstairs is also a method, you can also write form2.show in the onshow event of form1
Reply

Use magic Report

2

Threads

4

Posts

5.00

Credits

Newbie

Rank: 1

Credits
5.00

 China

 Author| Post time: 2020-5-9 09:00:01
| Show all posts
Yeah thank you first i am one
Reply

Use magic Report

2

Threads

4

Posts

5.00

Credits

Newbie

Rank: 1

Credits
5.00

 China

 Author| Post time: 2020-5-11 20:00:01
| Show all posts
You can start two windows, but there is still a problem. If I click on the CHANGE button continuously, EXCEPTION will appear.
Reply

Use magic Report

You have to log in before you can reply Login | Register

Points Rules

Contact us|Archive|Mobile|CopyRight © 2008-2023|verysource.com ( 京ICP备17048824号-1 )

Quick Reply To Top Return to the list