22/03/17 7:29
Goblin
La strada più facile è usare la classe (oggetto) TScreen docs.embarcadero.com/products/rad_studio/delphiAndcpp2009/HelpUpdate2/EN/html/delphivclwin32/…
Se invece vuoi complicarti la vita, ma con una maggiore flessibilità, allora ti scrivi una piccola classe che gestisce a tuo piacimento le varie form.
Saluti
G.
Se invece vuoi complicarti la vita, ma con una maggiore flessibilità, allora ti scrivi una piccola classe che gestisce a tuo piacimento le varie form.
Saluti
G.
Ibis redibis non morieris in bello
22/03/17 9:01
smanettone83
Ciao Goblin e grazie mille per le info. Diciamo che usando la classe Tscreen funziona pero ho ancora un dubbio.. c'e' un modo per identificare il numero del form in questione? oppure vanno in ordine crescente? cioe' se ho 200 form il numero 0 sara il primo che ho creato il numero 1 sara il secondo che ho creato e cosi via?? non c'e' un altro modo per identificare il form tipo tramite tag o simili? se io non conosco quale e' l'ordine numerico dei form che ho nel progetto come faccio? spero tu abbia capito.
Grazie ancora
Grazie ancora
aaa
22/03/17 9:48
Goblin
Ciao,
Mi spiace ma le uniche info che ti posso dare sono le stesse che leggo nella wiki di embarcadero:
Use Forms to access a form by index. The value of Index is a number between zero (the first form) and FormCount - 1. Forms can be used with FormCount when an application needs to iterate over all its forms, including all dialogs.
Forms only lists the TForm descendants in the application. This does not include, for example, property pages. To get a list that includes TCustomForm descendants that do not descend from TForm, use CustomForms instead.
Warning: The order in which Forms lists its forms is affected by the Z order of the forms. Do not change the Z order of forms when using Forms to iterate over the forms in an application.
Ma ciò non toglie che ci vuole poco per scrivere 2 righe di codice che ti ritorna l'indice della form da aprire passando un tag o un il nome.
Qualcosa del tipo
Ovviamente devi avere una lista di nomi, oppure di Tag univoci, assegnati ogni volta che una form viene creata.
Oppure un oggetto in ascolto ogni volta che una form viene creata o distrutta con dentro la lista, la descrizione, il tag o quello che desideri e gli indici delle form al momento "vive" nella tua applicazione, interrogando questo oggetto in base ai tuoi parametri lui ti ritorna l'indice della form desiderata e a quel punto basta la chiamata: Screen.Forms[indice].ShowModal.
Spero di aver capito la tua richiesta.
Saluti
G.
Mi spiace ma le uniche info che ti posso dare sono le stesse che leggo nella wiki di embarcadero:
Use Forms to access a form by index. The value of Index is a number between zero (the first form) and FormCount - 1. Forms can be used with FormCount when an application needs to iterate over all its forms, including all dialogs.
Forms only lists the TForm descendants in the application. This does not include, for example, property pages. To get a list that includes TCustomForm descendants that do not descend from TForm, use CustomForms instead.
Warning: The order in which Forms lists its forms is affected by the Z order of the forms. Do not change the Z order of forms when using Forms to iterate over the forms in an application.
Ma ciò non toglie che ci vuole poco per scrivere 2 righe di codice che ti ritorna l'indice della form da aprire passando un tag o un il nome.
Qualcosa del tipo
Function TFMain.GetMyForm(sName: String; nTag: Integer): Integer; Var x: Integer; begin Result := -1; if sName = '' then // ricerco x tag begin for x := 0 to Screen.FormCount-1 do if Screen.Forms[x].Tag = nTag then begin Result := x; break; end; end else // ricerco x nome begin for x := 0 to Screen.FormCount-1 do if Screen.Forms[x].Name = sName then begin Result := x; break; end; end; end; ........ // ricerca per nome nForm := GetMyForm('pippo', -1); // ricerca per tag nForm := GetMyForm('', 3); if nForm > 0 then Screen.Forms[nForm].ShowModal else if nForm = 0 then showmessage('Form principale') else showmessage('Form non trovata');
Ovviamente devi avere una lista di nomi, oppure di Tag univoci, assegnati ogni volta che una form viene creata.
Oppure un oggetto in ascolto ogni volta che una form viene creata o distrutta con dentro la lista, la descrizione, il tag o quello che desideri e gli indici delle form al momento "vive" nella tua applicazione, interrogando questo oggetto in base ai tuoi parametri lui ti ritorna l'indice della form desiderata e a quel punto basta la chiamata: Screen.Forms[indice].ShowModal.
Spero di aver capito la tua richiesta.
Saluti
G.
Ibis redibis non morieris in bello