Ian Branch 127 Posted January 16, 2021 Hi Team, D10.4.1, Win 10, 32bit App. I need to open a sub form, StockPositionForm, from the MainForm, non modal as it is used in conjunction with other forms in the App. At the same time I need to prevent StockPositionForm being reopened again from the MainForm whilst StockPositionForm is already open. StockPositionForm is currently opened with.. procedure TMainForm.StockPosition1Click(Sender: TObject); begin // TStockPositionForm.Create(Self).Show; // end; Thoughts/suggestions, polite :-), appreciated. Regards & TIA, Ian Share this post Link to post
Attila Kovacs 629 Posted January 16, 2021 (edited) what a coincidence, if you look at Remy's answer, you will get the idea. Edited January 16, 2021 by Attila Kovacs Share this post Link to post
Ian Branch 127 Posted January 16, 2021 Ahhhh. Excellent! Works perfectly. Thank you. Regards, Ian Share this post Link to post
Guest Posted January 17, 2021 (edited) 6 hours ago, Ian Branch said: At the same time I need to prevent StockPositionForm being reopened again from the MainForm whilst StockPositionForm is already open. that way is more easy and can be used in another forms. using "Create(Application)" the application end and release it! the "StockPositionForm" will be release only when app end, else, same clicking on "closse buttton" it will be "hided" - not closed! FormMain: type TFormMain = class(TForm) Button1: TButton; Button2: TButton; procedure Button1Click(Sender: TObject); procedure Button2Click(Sender: TObject); procedure FormCreate(Sender: TObject); private { Private declarations } public { Public declarations } end; var FormMain: TFormMain; procedure prcShowStockPositionForm; // exported for another units! implementation {$R *.dfm} uses uStockPositionForm, uFormSecond; procedure prcShowStockPositionForm; // for easy use! but you can put it in a unit generic for general use!!! begin // use same var "StockPositionForm : TStockPositionForm" definided on "uStockPositionForm.pas" // // always verifying if "it" was not created... then, create it! if (StockPositionForm = nil) then StockPositionForm := TStockPositionForm.Create(Application); // // if it is not showing... (if hide for example) if not StockPositionForm.Showing then StockPositionForm.Show else StockPositionForm.BringToFront; end; procedure TFormMain.Button1Click(Sender: TObject); begin prcShowStockPositionForm; end; procedure TFormMain.Button2Click(Sender: TObject); begin FormSecond := TFormSecond.Create(nil); try FormSecond.ShowModal; finally FreeAndNil(FormSecond); end; end; procedure TFormMain.FormCreate(Sender: TObject); begin Self.Position := TPosition.poScreenCenter; end; initialization ReportMemoryLeaksOnShutdown := true; finalization end. FormSecond type TFormSecond = class(TForm) Button1: TButton; procedure Button1Click(Sender: TObject); procedure FormCreate(Sender: TObject); private { Private declarations } public { Public declarations } end; var FormSecond: TFormSecond; implementation {$R *.dfm} uses uFormMain; // necessary to use "prcShowStockPositionForm;" but you can put this procedure in a unit for general use (not in FormMain) procedure TFormSecond.Button1Click(Sender: TObject); begin prcShowStockPositionForm; end; procedure TFormSecond.FormCreate(Sender: TObject); begin Self.Height := 200; Self.Width := 600; Self.Position := TPosition.poScreenCenter; end; end. StockPositionForm type TStockPositionForm = class(TForm) procedure FormCreate(Sender: TObject); private { Private declarations } public { Public declarations } end; var StockPositionForm: TStockPositionForm; implementation {$R *.dfm} uses uFormMain; // not necessary! here only because below: FormMain.Left ... and .Top procedure TStockPositionForm.FormCreate(Sender: TObject); begin Self.Left := FormMain.Left + FormMain.Width + 50; Self.Top := FormMain.Top; end; end. hug Edited January 17, 2021 by Guest Share this post Link to post