query

AbhiJeet
AbhiJeet used Ask the Experts™
on
Experts,

Stuck with a prob as below:

i have a form, on the form i have a button and an edit box. I have another form, and an edit box there also. on clicking the form 1 button i need to show the text of form1's edit box into form2's text box.

Can anyone suggest with code?
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®

Commented:
On button click event

Form2.Edit1.Text:=Form1.Edit1.Text;

Regards,
B.

Commented:
unit Unit1;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, StdCtrls;

type
  TForm1 = class(TForm)
    Edit1: TEdit;
    Button1: TButton;
    procedure Button1Click(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  Form1: TForm1;

implementation

{$R *.dfm}

uses unit2;

procedure TForm1.Button1Click(Sender: TObject);
begin
form2.Edit1.Text := Form1.Edit1.Text;
form2.Show;
end;

end.

Open in new window

Author

Commented:
this is not working, form2.edit1 is not accessible.
OWASP: Avoiding Hacker Tricks

Learn to build secure applications from the mindset of the hacker and avoid being exploited.

Oracle dba
Top Expert 2009
Commented:
again ... not very nice to use form1 or form2

doesn't anybody ever consider using 1 form into 100+ projects ?
why do so many developers make so many forms over and over and over ...

unit Unit1;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, StdCtrls;

type
  TForm1 = class(TForm)
    Edit1: TEdit;
    Button1: TButton;
    procedure Button1Click(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  Form1: TForm1;

implementation

{$R *.dfm}

uses uInfo;

procedure TForm1.Button1Click(Sender: TObject);
begin
  ShowInfo('info', Edit1.Text);
end;

end.

Open in new window

unit uInfo;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, StdCtrls;

type
  TfrmInfo = class(TForm)
    lblHeader: TLabel;
    lblInfo: TLabel;
    btnOk: TButton;
    procedure btnOkClick(Sender: TObject);
  end;

var
  frmInfo: TfrmInfo;

procedure ShowInfo(aHeader, aInfo: string);

implementation

{$R *.dfm}

procedure ShowInfo(aHeader, aInfo: string);
var frm: TfrmInfo;
begin
  frm := TfrmInfo.Create(Application);
  try
    frm.lblHeader.Caption := aHeader;
    frm.lblInfo.Caption := aInfo;
    frm.ShowModal;
  finally
    FreeAndNil(frm);
  end;
end;

procedure TfrmInfo.btnOkClick(Sender: TObject);
begin
  Close;
end;

end.

Open in new window

Commented:
Ok, here's an attach file, please click and download it.
 form1andform2.zip
open the .dpr file
Geert GOracle dba
Top Expert 2009

Commented:
systan,

this is a solution in which unit1 is totally dependant on
 * the existance of unit2
 * form2 existing in unit2

if you copy unit1 into a other project
then it will by default not work

i guess most developers have to write millions of line of code
and after writing all that code they start to wonder:
  " why is it that i have so many same forms in all those projects ?... "
  " wouldn't it be possible to use 1 same form in all projects ?"

well .. no ... cause unit1 depends on unit2
and unit34 depends on unit27
and unit62 depends on unit52
etc ... etc .. etc
.. so i'll do the quick and dirty ... i'll copy ALL the units to the new project :)
and just change where needed.

I guess that's why AbhiJeet is asking these questions
or am i mistaken AbhiJeet ?

Commented:
yes,
I understand Geert,
thank you,

next time,  I will,   I hope to remember that.


So, to be sure for a simple sample code, I attached a project file.
Geert GOracle dba
Top Expert 2009

Commented:
i still don't understand why so many "experts" display so much bad practices

* not renaming components/forms/units
* making units interdependant on each other >> causing circular unit reference
* using the global form variables inside implementation sections of other units

your sample contains all these bad practices systan ... FactorB too for that matter

Commented:
Actually, it's easier to find out or understand of we'll use default components/forms/units FOR us.

I believed in you Geert,   but for the asker,  the way I see,  he needs a very simple sample that includes the whole project folder.   That's why I attached the project file.  That's only for now,  soon?, it can be managed.

In my other projects, I always listen and implement what you've said geert.


thanks tor Ex-Ex Delphi experts, I'll reach my Guru Level soon this month.
Even thought I suffer to compete answering with good experts here, like you, epasquier, ewangoya and jimyX,   I still continue.

Don't worry Geert, were following your suggestions.
Top Expert 2014

Commented:
@Geert

You missed a great opportunity to drive readers to your excellent Delphi articles, such as the Black Box Technique
http://www.experts-exchange.com/A_1285.html
Geert GOracle dba
Top Expert 2009

Commented:
it's not that good an article ...
i'm still trying to figure out the best approach at explaining
i'm not so good in article writing skills

it's a start of how you can use a single unit to link different units to a project
changing this unit can link different units to a project

Commented:
Another too
Mike McCrackenSenior Consultant
Most Valuable Expert 2011
Top Expert 2013

Commented:
This question has been classified as abandoned and is closed as part of the Cleanup Program. See the recommendation for more details.

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial