Icon View Thread

The following is the text of the current message along with any replies.
Messages 1 to 5 of 5 total
Thread Sending Information from a Form to a Subsequent Form
Sun, Oct 4 2015 9:57 PMPermanent Link

Richard Harding

Wise Nutrition Coaching

I wish to pass information that has been obtained from a form to a subsequent form.

The following code is in the first form and is performed when a edit control is clicked.  The name of the control that is clicked is stored in the public declarations of the second form, fmStockOptions form.

function TfmStockDetail.edTypeButtonClick(Sender: TObject): Boolean;
begin
  fmStockOptions := TfmStockOptions.Create(nil);
  fmStockOptions.OriginTextBox := TComponent(Sender).Name;
  ShowMessage('Clicked control: ' + fmStockOptions.OriginTextBox);   // Shows name of clicked control
  fmStockOptions.OnClose := fmStockOptionsClose;
  fmStockOptions.ShowModal;
end;

I wish to get access to the name of the clicked control in the fmStockOptions OnShow event.

procedure TfmStockOptions.fmStockOptionsShow(Sender: TObject);
begin
  ShowMessage('OnShow: ' + OriginTextBox);       // Displays an empty string
end;

How can I do this?
Thank you.

Richard Harding.
Mon, Oct 5 2015 8:45 AMPermanent Link

Raul

Team Elevate Team Elevate

On 10/4/2015 9:57 PM, Richard Harding wrote:
> function TfmStockDetail.edTypeButtonClick(Sender: TObject): Boolean;
> begin
>     fmStockOptions := TfmStockOptions.Create(nil);

I will assume your TfmStockOptions form "Visible" property is set to
true in which case this results in form actually also showing (and
firing the OnShow event). In your case you also call ShowModal which
does not really affect form visibility at that point.

> I wish to get access to the name of the clicked control in the fmStockOptions OnShow event.
> procedure TfmStockOptions.fmStockOptionsShow(Sender: TObject);
> begin
>     ShowMessage('OnShow: ' + OriginTextBox);       // Displays an empty string
> end;
>
> How can I do this?

Cleanest option IMHO is to simply create a custom form constructor which
accepts any extra parameters.

Alternative is to set the Visible to False and then OnShow should not
fire until you actually call ShowModal.

Raul
Mon, Oct 5 2015 9:42 PMPermanent Link

Richard Harding

Wise Nutrition Coaching

<<Cleanest option IMHO is to simply create a custom form constructor which accepts any extra parameters.

Alternative is to set the Visible to False and then OnShow should not fire until you actually call ShowModal.>>

Thank you, Raul.

I did as you suggested - created another constructor for the form with the required parameter.  I still needed to set the Visible property of the form to False.

All working now - thank you.

Richard Harding
Tue, Oct 6 2015 12:06 AMPermanent Link

Raul

Team Elevate Team Elevate

On 10/5/2015 9:42 PM, Richard Harding wrote:
>
> I did as you suggested - created another constructor for the form with the required parameter.  I still needed to set the Visible property of the form to False.

Where are you storing the parameter - if you store it in class before
calling inherited create it should also work with visible property being
true.

i.e. something like this

constructor TMyForm.CreateWithOrigin(AOwner: TComponent;Origintext:String);
begin
  FOriginText := Origintext;
  inherited Create(AOwner);
end;


Raul
Thu, Oct 8 2015 12:32 AMPermanent Link

Richard Harding

Wise Nutrition Coaching

Hi Raul
<<
constructor TMyForm.CreateWithOrigin(AOwner: TComponent;Origintext:String);
begin
  FOriginText := Origintext;
  inherited Create(AOwner);
end;
>>

Yes, I was assigning the parameter after the inherited statement.

Thank you . . . . still learning.

Richard
Image