Click here to Skip to main content
15,879,348 members
Please Sign up or sign in to vote.
3.00/5 (1 vote)
See more:
I would like to pass the Values below in form1 that are assigned to the variables userid, name and privilege to form2 . How do i do that? please help

Delphi
procedure TForm1.Button1Click(Sender: TObject);
var
 name,pasword, privilege:string;
     UserId: Integer;

begin

        IBQuery1.SQL.clear;
        IBQuery1.SQL.add('Select * from USER_ACCESS where USERID = '+ edit1.Text+'') ;
        IBQuery1.Active := true;
        UserId := IBQuery1.FieldByname('USERID').AsInteger;
        pasword:= IBQuery1.Fieldbyname('PASWORD').AsString;
     name := IBQuery1.fieldbyname('NAME').AsString;
        privilege := IBQuery1.fieldbyname('USERTYPE').AsString;
        if((UserId = StrToInt(edit1.Text)) And (pasword = edit2.Text))
         THEN
          begin
        ShowMessage('login Successful ' + name);
   Form2.Show;
   Form1.Hide;

        end

        else
        ShowMessage('Wrong Password');

        end;
Posted

In your question, it's not quite clear where is the form types, and where are the instances of the forms. First of all, avoid naming like TForm1, Form1, etc. Give everything semantic names. I assume you already passes some instance of TForm2 to Form1, and the names of the instances match the names of the types (this is not apparent from your question; if you use automatically generating names, it should be the case, but you should not use such names).

Now, you need to have appropriate member(s) of Form2 to accept the values you need to pass, and make those members accessible (public). Then just do the assignment. The problem of using the form instances is this: it compromises type encapsulation. When you pass an instance to the form to other form, you usually pass too much of access. The really robust solution is to declare an interface for such collaboration and implement it in one of the forms. Then, you can pass the interface pointer (reference) to other form, giving the access only through the interface members (methods or properties).

I hope you know how to declare and implement interfaces.

—SA
 
Share this answer
 
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900