#1
  1. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Oct 2012
    Location
    São Paulo - Brazil
    Posts
    35
    Rep Power
    3

    Receiving parameters from a Form


    Suppose I need to receive a TMemo and boolean(meaning confirm or deny) from a form.

    I show the Form asking for the reason of record deletion. The user type the reason and clicks a button informing if he confirm or deny the deletion.

    How can I receive the boolean and TMemo without use public variables? When I create a form I can pass the arguments via CREATOR parameters. Is there a similar way to receive parameters back from a form?

    Greetings from São Paulo - Brazil

    Ricardo
  2. #2
  3. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jun 2008
    Posts
    356
    Rep Power
    7
    While you can use PUBLIC variables for such a task, it's best if you use private variables, and then provide public methods that can set the values of these private variables.
    Code:
    unit MyPrimaryUnit;
    
    interface
    
    uses ...
    
    type
    
    TMyPrimaryForm = class(TForm)
      ...
    private
       MyPrivateVariable: String;
       ...
    public
       SetPrivateVariable(Value: String);
       ...
    end;
    
    procedure TMyPrimaryForm.SetPrivateVariables(Value: String);
    begin
       MyPrivateVariable := Value;
    end;
    Then in your secondary form
    Code:
    unit MySecondaryUnit;
    
    interface
    
    uses ..., MyPrimaryUnit;
    
    type
    
    TMySecondaryForm = class(TForm)
       ...
       procedure FormClose(Sender: TObject);
    end;
    
    procedure TMySecondaryForm.FormClose(Sender: TObject);
    var
       MyValue: String;
    begin
       MyValue := Memo1.Text;
       MyPrimaryForm.SetPrivateVariable(MyValue);
       ...
    end;

IMN logo majestic logo threadwatch logo seochat tools logo