was ist neu ¦  programmier tips ¦  indy artikel ¦  intraweb artikel ¦  informationen ¦  links ¦  interviews
 sonstiges ¦  tutorials ¦  Add&Win Gewinnspiel

Tips (1541)

Dateien (137)
Datenbanken (90)
Drucken (35)
Grafik (114)
IDE (21)
Indy (5)
Internet / LAN (130)
IntraWeb (0)
Mathematik (76)
Multimedia (45)
Oberfläche (107)
Objekte/
ActiveX (51)

OpenTools API (3)
Sonstiges (126)
Strings (83)
System (266)
VCL (242)

Tips sortiert nach
Komponente


Tip suchen

Tip hinzufügen

Add&Win Gewinnspiel

Werbung

39 Visitors Online


 
...die Hauptform zur Laufzeit wechseln?
Autor: Ahmed Ammar
[ Tip ausdrucken ]  

Tip Bewertung (56):  
     


procedure SetAsMainForm(aForm:TForm);
var
  
P:Pointer;
begin
  
P := @Application.Mainform;
  Pointer(P^) := aForm;
end;

{************************************}

// Example of Usage:

{
Question:

  If my application is main.exe and the main form is form1, form1 displays
  when it runs. I would like to display other forms based on the parameter
  passed.
  main.exe param1 will display form2 as the first form
  main.exe param2 with display form3 as the first form

Answer:
}

program Project1;

uses
  
Forms,
  Unit1 in 'Unit1.pas' {Form1},
  Unit2 in 'Unit2.pas' {Form2},
  Unit3 in 'Unit3.pas' {Form3};

{$R *.res}

procedure SetAsMainForm(aForm:TForm);
var
  
P:Pointer;
begin
  
P := @Application.Mainform;
  Pointer(P^) := aForm;
end;

begin
  
Application.Initialize;
  Application.CreateForm(TForm1, Form1);
  Application.CreateForm(TForm2, Form2);
  Application.CreateForm(TForm3, Form3);

  if Paramstr(1) = 'Param1' then
    
SetAsMainForm(Form2);

  if Paramstr(1) = 'Param2' then
    
SetAsMainForm(Form3);

  Application.Run;
end.

 

Bewerten Sie diesen Tipp:

dürftig
ausgezeichnet


Copyright © by SwissDelphiCenter.ch
All trademarks are the sole property of their respective owners