The OnCreate handler of the main form is more or less the"standard" place, because normally it's called only once at the start of the program.
I have seen people put it (conditionally) in the OnShow event and I myself use the OnActivate handler when I have first to make sure the form and controls are completely initialized before loading any file.
But most of the times, the OnCreate handler is the proper one.
procedure TfrmFrmMain.FormShow(Sender: TObject);
begin
if (ParamCount > 0) and (FileExists(ParamStrUTF8(1))) and (UTF8LowerCase(ExtractFileExt(ParamStrUTF8(1))) = '.xyz') then
OpenMyFile(ParamStrUTF8(1));
end;
The problem with that code is that the OnShow event is trigered on many conditions, not just on starting the program, so you keep (re-)loading the parameters at odd moments during the application run-time.
If for whatever reason you want to make it in OnShow, use something like:
procedure TfrmFrmMain.FormCreate(Sender: TObject);
begin
ParamsLoaded := False;
end;
procedure TfrmFrmMain.FormShow(Sender: TObject);
begin
if not ParamsLoaded then begin
if (ParamCount > 0) and (FileExists(ParamStrUTF8(1))) and (UTF8LowerCase(ExtractFileExt(ParamStrUTF8(1))) = '.xyz') then
OpenMyFile(ParamStrUTF8(1));
ParamsLoaded := True;
end;
end;
Or if you use OnShow just for that:
procedure TfrmFrmMain.FormShow(Sender: TObject);
begin
OnShow := Nil; {Make sure it's called only once}
if (ParamCount > 0) and (FileExists(ParamStrUTF8(1))) and (UTF8LowerCase(ExtractFileExt(ParamStrUTF8(1))) = '.xyz') then
OpenMyFile(ParamStrUTF8(1));
end;