How to get value from one form to another?

5

I have form 1 and it has a field that in the onExit action I search the code in the bank and if it does not, I'll send a message if I want to register a product. If yes opens form 2, now I am not able to get the generated field and send 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 Code field, follow the code:

ModalResult := mrYes;
    
asked by anonymous 15.12.2015 / 15:06

1 answer

5

Your approach is strange, I could not identify some properties reading your Code!

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

Declare a Public variable on your Form 1, when you click Save do something like:

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 Text property should receive String, if it was registered in the Integer variable, should convert: IntToStr(NovoCodigo) .

    
15.12.2015 / 16:04