Recent

Author Topic: Problem using 2 forms in a program  (Read 6333 times)

yordan

  • New Member
  • *
  • Posts: 18
Problem using 2 forms in a program
« on: January 11, 2011, 01:01:22 pm »
 Hi, I'm trying to write a program that uses 2 forms. The idea is when you click on one of the edit boxes in form1 and press Enter form2 pops out(form 2 has a dbgrid that shows the content of a table in mysql database). When click on a row in the dbgrid in form2 the values of the table(it contains 2 fields kod and name) should be assigned to edit boxes in form1. The code i use is:
 for form1:
 unit Unit1;
uses
  Classes, SysUtils, db, sqldb, mysql50conn, FileUtil, Forms, Controls,
  Graphics, Dialogs, ExtCtrls, StdCtrls, ComCtrls, DBGrids, unit2, LCLType;
....
procedure TForm1.Edit3KeyPress(Sender: TObject; var Key: char);
begin
  if Key= #13 then
   form2.showmodal;
end;                     
 And in form2 I use:
uses
  Classes, SysUtils, db, sqldb, unit1, mysql50conn, FileUtil, Forms, Controls,
  Graphics, Dialogs, DBGrids, StdCtrls, ComCtrls;     
...............................................................
procedure TForm2.DBGrid1CellClick(Column: TColumn);
begin
   form1.Edit3.Text:=DBGrid1.Columns[0].Field.AsString;
   form1.Edit4.Text:=Dbgrid1.Columns[1].Field.AsString;
end;           
 But I get the following error message:"unit2.pas(8,38) Fatal: Circular unit reference between Unit2 and Unit1"             
 When I delete unit1 from the uses clause in form2 Lazarus doesn't recognize form1.Edit3.Text:=DBGrid1.Columns[0].Field.AsString; 
 If anyone has ideas how to deal with this I'd be very grateful.
                           

Blaazen

  • Hero Member
  • *****
  • Posts: 3241
  • POKE 54296,15
    • Eye-Candy Controls
Re: Problem using 2 forms in a program
« Reply #1 on: January 11, 2011, 01:13:39 pm »
You have to write it down to implementation section:

Code: [Select]
interface

uses
  Classes, SysUtils, db, sqldb, unit1, mysql50conn, FileUtil, Forms, Controls,
  Graphics, Dialogs, DBGrids, StdCtrls, ComCtrls; 

....

implementation

uses Unit1;

procedure .......

to avoid the circular reference.
Lazarus 2.3.0 (rev main-2_3-2863...) FPC 3.3.1 x86_64-linux-qt Chakra, Qt 4.8.7/5.13.2, Plasma 5.17.3
Lazarus 1.8.2 r57369 FPC 3.0.4 i386-win32-win32/win64 Wine 3.21

Try Eye-Candy Controls: https://sourceforge.net/projects/eccontrols/files/

yordan

  • New Member
  • *
  • Posts: 18
Re: Problem using 2 forms in a program
« Reply #2 on: January 11, 2011, 01:38:21 pm »
Thanks, it works now :)

eny

  • Hero Member
  • *****
  • Posts: 1647
Re: Problem using 2 forms in a program
« Reply #3 on: January 11, 2011, 04:09:41 pm »
And maybe an email to the admin that the search function is broken ?  O:-)
All posts based on: Win10 (Win64); Lazarus 3_4  (x64) 25-05-2024 (unless specified otherwise...)

Marc

  • Administrator
  • Hero Member
  • *
  • Posts: 2650
Re: Problem using 2 forms in a program
« Reply #4 on: January 11, 2011, 04:13:28 pm »
And maybe an email to the admin that the search function is broken ?  O:-)
What search function ?
//--
{$I stdsig.inc}
//-I still can't read someones mind
//-Bugs reported here will be forgotten. Use the bug tracker

 

TinyPortal © 2005-2018