On the main form I create a string variable s . I assign it to the edit y value on a third-party form, everything is perfectly assigned, but if I connect the sql , then when I run the application, this variable turns out to be null , where is my error?

I assign and send to the form

 s := ADOQuery2.Fields.Fields[0].AsString; form4.Edit4.text := s; 

at the same time everything works without requests.
when opening the desired form, I want to use the value of this edit -a

 ADOQuery1.Parameters.ParamByName('a').Value := strToInt(edit3.Text); ADOQuery1.ExecSQL; 

here the program detects null , how do I get around this?

  • There is a global variable, in it I store the employee code for authentication. Employees make sales on form 4. When a sale is added, the employee code is automatically recorded in the sales table, so this variable is empty for some reason (the program says so at startup) - element111
  • What is the relationship between Edit4 and edit3 ? - Igor
  • I messed up a bit, sorry, and there and there Edith 3. but that's not the point - element111
  • 3
    The phrase "when you open the desired form" makes sense only for you. People who are hundreds or thousands of kilometers away from you cannot look into your brain. Use Delphi terms and code if you want to be understood. - Igor

2 answers 2

If I understand you correctly, I will send you a sample code

Form number 1

 unit Unit1; interface uses Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants, System.Classes, Vcl.Graphics, Vcl.Controls, Vcl.Forms, Vcl.Dialogs, Vcl.StdCtrls, Data.DB, Data.Win.ADODB,Unit2; type TForm1 = class(TForm) ADOQuery1: TADOQuery; Edit1: TEdit; Button1: TButton; ADOQuery1ID: TFMTBCDField; procedure Button1Click(Sender: TObject); end; var Form1: TForm1; implementation {$R *.dfm} procedure TForm1.Button1Click(Sender: TObject); var form2: TForm2; S: string; begin ADOQuery1.Open; S := ADOQuery1.FieldByName('ID').AsString; Edit1.Text := S; form2 := TForm2.Create(Self); form2.Edit1.Text := S; form2.ShowModal; end; end. 

Form # 2

 unit Unit2; interface uses Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants, System.Classes, Vcl.Graphics, Vcl.Controls, Vcl.Forms, Vcl.Dialogs, Vcl.StdCtrls, Data.DB, Data.Win.ADODB, Vcl.Grids, Vcl.DBGrids; type TForm2 = class(TForm) ADOQuery1: TADOQuery; Edit1: TEdit; Button1: TButton; DBGrid1: TDBGrid; DataSource1: TDataSource; procedure Button1Click(Sender: TObject); end; var Form2: TForm2; implementation {$R *.dfm} procedure TForm2.Button1Click(Sender: TObject); begin ADOQuery1.Parameters.ParamByName('A').Value := Edit1.Text; ADOQuery1.Open; end; end. 

    The most obvious answer - Edit3 has not (already) been created at the moment when you assign it. Or not yet initialized. Without a code, nothing else can be answered.

    • Not the answer - Kromster