I have a "hack" that works perfectly. I have a Mainform with a submenu and several Tag properties (e.g frmMainform.mnuCustomer.Tag) that are the names of tables using the same form in my application.
The submenu items call the same form (frmShowData) BUT display data from different databases based on which submenuitem was clicked.
A) Mainform code
The code below ensures that my "showdata" unit is visible to my "mainform" unit
unit mainmenu;
interface
...
implementation
uses showdata;
When a submenuitem, say Customers is clicked for example, the following code is executed. The code that displays the Suppliers is similar to the code that displays Customers
procedure TfrmMainform.mnuCustomersClick(Sender: TObject);
begin
// Set the tag variable of the submenu to 1
mnuCustomers.Tag := 1;
// Open the 'ShowData' form
ShowData.Show;
// Reset the tag variable of the submenu to zero
mnuCustomers.Tag := 0;
end;
B) ShowData - shows data from either the Customer or Supplier tables
The code below ensures that my "mainform" unit is "visible" to my "showdata" unit
unit showdata;
interface
...
implementation
uses mainform;
FormShow "showdata" procedure
procedure TfrmShowData.FormShow(Sender: TObject);
begin
if frmMainform.mnuCustomers.Tag = 1 then // 'Customer'
// Show form with customer data
else if frmMainform.mnuSuppliers.Tag = 1 then // 'Suppliers'
begin
// Show form with supplier data
end;
.
.
.
end;
That's all! Hope you'll find it useful.
