Recent

Author Topic: passing parameter to a form  (Read 9174 times)

RobyWan

  • New Member
  • *
  • Posts: 13
passing parameter to a form
« on: October 28, 2010, 05:25:48 pm »
Hi everibody!
I need to build a form in which to show data from different tables of my sql but with the same look (a search mask with navigation and table)
If the parameter is, for example, 'A', I show data from table 'Customers'; if parameter is 'B' i show data from table 'Items', and so on.
How I have to do?

Thanks in adavance.

My Lazarus 0.9.29 svn 27658 12/10/2010


mas steindorff

  • Hero Member
  • *****
  • Posts: 566
Re: passing parameter to a form
« Reply #1 on: October 28, 2010, 05:56:06 pm »
are you asking
1: how to share a component acress forms
2: how to pass /exchange info between forms
or 3: something to do with data bases
?
windows 10 &11, Ubuntu 21+ IDE 3.4 general releases

jixian.yang

  • Full Member
  • ***
  • Posts: 173
Re: passing parameter to a form
« Reply #2 on: October 29, 2010, 01:43:52 am »
Do you mean:

ParamStr(1) ?

Martin_fr

  • Administrator
  • Hero Member
  • *
  • Posts: 12202
  • Debugger - SynEdit - and more
    • wiki
Re: passing parameter to a form
« Reply #3 on: October 29, 2010, 01:56:11 am »
Ok, there is quite an information Gap, but...

I assume you have 2 Forms (Form1, Form2)

1) You mean how can your first Form in unit1 refer to your 2nd Form in unit2?
add "unit2" to the uses clause in unit1.
If Form2 also needs to refer to Form1, then you can add unit1 to unit2 too; but you must add a "uses" clause in the implementation section of unit 2
Code: [Select]
unit unit2;
interface
   ...
implementation
uses Unit2;

2) You mean at some point (like a button on Form1 pressed), your Form1 calls Form2 like "Form2.Show"

Now in Form2.OnShow you want to change what data to display. So at this point unit1 should have passed some info...

a) You can add some properties to Form2

Code: [Select]
private
  FDataSetIndex: Integer
public
  property DataSetIndex: Integer read FDataSetIndex write FDataSetIndex;

then in form1 you do
Code: [Select]
   Form2.DataSetIndex := 999;
  Form2.Show;

b) introduce your own show
In Form2 declare
Code: [Select]
  public
  procedure MyShow(DataSetIndex: Integer);

Code: [Select]
  procedure TForm2MyShow(DataSetIndex: Integer);
  begin
    // prepare your data
    Show;
    // morechanges to the data, if needed
  end;


JD

  • Hero Member
  • *****
  • Posts: 1910
Re: passing parameter to a form
« Reply #4 on: October 29, 2010, 08:18:43 am »
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
Code: [Select]
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
Code: [Select]
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
Code: [Select]
unit showdata;                
interface
   ...
implementation
uses mainform;

FormShow "showdata" procedure
Code: [Select]
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.  :D
« Last Edit: October 29, 2010, 08:44:44 am by JD »
Linux Mint - Lazarus 4.0/FPC 3.2.2,
Windows - Lazarus 4.0/FPC 3.2.2

mORMot 2, PostgreSQL & MariaDB.

RobyWan

  • New Member
  • *
  • Posts: 13
Re: passing parameter to a form
« Reply #5 on: October 29, 2010, 09:21:50 am »
Thank to everibody!
Next time I'll be more clear in my explanation.
Howewer you all have correctly understand my need.
Thanks again

thierrybo

  • Full Member
  • ***
  • Posts: 146

 

TinyPortal © 2005-2018