User Tools

Site Tools


checkparametersbeforecreateform

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revisionPrevious revision
Next revision
Previous revision
checkparametersbeforecreateform [2025/04/18 03:25] jwancheckparametersbeforecreateform [2025/10/10 10:15] (current) – external edit 127.0.0.1
Line 111: Line 111:
  
  
 +Another is to create different form base on the parameter:
 +
 +<code>
 +program Project1;
 +
 +uses
 +  Forms, Dialogs, SysUtils, Unit1 in 'Unit1.pas', Unit2 in 'Unit2.pas';
 +
 +{$R *.RES}
 +
 +const
 +  ProgramVersion = '1.0.0'; // Define the program version
 +
 +begin
 +  Application.Initialize;
 +
 +  // Check for command-line parameters
 +  if ParamCount > 0 then
 +  begin
 +    if SameText(ParamStr(1), '/scan') then
 +    begin
 +      // If the parameter is "/scan", create and display TScanForm (Unit2)
 +      Application.CreateForm(TScanForm, ScanForm);
 +      Application.Run;
 +      Exit;
 +    end
 +    else if SameText(ParamStr(1), '/help') then
 +    begin
 +      // If the parameter is "/help", show help text and exit
 +      MessageBox(0, PChar('Program Version: ' + ProgramVersion + sLineBreak +
 +                          'Usage:' + sLineBreak +
 +                          '/scan - Run scan mode (no default form).' + sLineBreak +
 +                          '/help - Display this help message.'), 
 +                          'Help', MB_ICONINFORMATION or MB_OK);
 +      Halt; // Terminate the program
 +    end;
 +  end;
 +
 +  // If no parameters or unrecognized parameter, create and display TForm1
 +  Application.CreateForm(TForm1, Form1);
 +  Application.Run;
 +end.
 +</code>
 +
 +NOTE: just make sure each of the form will have:
 +
 +<code>
 +
 +public
 +    { Public declarations }
 +    constructor Create(AOwner: TComponent); override;
 +    
 +constructor Tformmain.Create(AOwner: TComponent);
 +begin
 +   inherited Create(AOwner); // Call the inherited constructor
 +end;
 +</code>
checkparametersbeforecreateform.1744946752.txt.gz · Last modified: (external edit)

Donate Powered by PHP Valid HTML5 Valid CSS Driven by DokuWiki