Link to home
Start Free TrialLog in
Avatar of AbhiJeet
AbhiJeet

asked on

query

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?
Avatar of FactorB
FactorB

On button click event

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

Regards,
B.
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

Avatar of AbhiJeet

ASKER

this is not working, form2.edit1 is not accessible.
ASKER CERTIFIED SOLUTION
Avatar of Geert G
Geert G
Flag of Belgium image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
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 ?
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.
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
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.
@Geert

You missed a great opportunity to drive readers to your excellent Delphi articles, such as the Black Box Technique
https://www.experts-exchange.com/A_1285.html
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
Another too
This question has been classified as abandoned and is closed as part of the Cleanup Program. See the recommendation for more details.