How to get value from one form to another?

Asked

Viewed 2,028 times

5

I have Form 1 and it has a field that in the action onExit I search the code in the bank and if not find I present a message if you want to register a product. If you open Form 2, now I’m not able to take the generated field and send it to Form 1, follow the template:

with form do
 begin
   form:=Tfrm_formulario2.Create(Application);
   Centraliza_Form(form);
   form.ShowModal;
   if(form.ShowModal=mrYes)then
      begin
         campo.campos^[2].valorInteiro:= form.campoCodigo.AsInteger; 
      end;
   Release; 
end

In form 2 in the save button action I want the screen to close and return the value of the fieldCodigo, follow the code:

ModalResult := mrYes;

1 answer

5


Your approach is strange, I couldn’t identify some properties reading your Code!

My approach would be to use global variables, as you want to close Form 2 and return to Form 1 by passing the data, so Form 2 data is inaccessible.

Declare a Publish variable in your Form 1, when you click Save do something like this:

procedure Formulario2.btnSalvarClick(Sender: TObject);
begin
  Formulario1.NomeVariavelPublica := NovoCodigo;
  Close;
end;

In Form 1 you pass the value of the variable: NomeCampo.text := NovoCodigo

Remembering that the property Text must receive String, if it was registered in the variable Integer must convert: IntToStr(NovoCodigo).

  • 1

    Vlw Junior, creating the global variable function right Aki :D

Browser other questions tagged

You are not signed in. Login or sign up in order to post.