I have two forms in Lazarus. one is frmMain and the other is frmSub1. both have a text box.
The following code works. i.e., on clicking a button on frmMain, the value
procedure TfrmMain.cmdShowClick(Sender: TObject);
begin
frmSub1.Show ;
frmSub1.txtAns.text := txtMark.Text;
end;
But when I replace .Show with .ShowModal, it shows the form but frmSub1.txtAns is blank.
Any idea why this is so?
Thats because ShowModal
is blocking call, ie the line frmSub1.txtAns.text := txtMark.Text;
wont execute until it returns. You have to switch the order of statements, following should work as you expect:
procedure TfrmMain.cmdShowClick(Sender: TObject);
begin
frmSub1.txtAns.text := txtMark.Text;
frmSub1.ShowModal;
end;