I'm working on a small Delphi project. I'm trying to link an TEdit
with another TEdit
.
When the user types his username and password and logs in, the username should show up in the next Form. I've created a TEdit
on the next Form, but I don't know to link it.
Can someone please help me?
I'm using Delphi 10.4!
CodePudding user response:
Well... you actually can link one TEdit
to another TEdit
(or, for that matter, any other component/control/property to any other component/control/property), but you will need to use LiveBinding, or kbmMW SmartBinding.
In kbmMW SmartBinding, you can do it in a couple of ways. In code:
Binding.Bind(Edit1,'Text',Edit2,'Text');
One way binding. If you change Edit1.Text
somehow (by typing or by code), Edit2.Text
will automatically be updated. But, if you change Edit2.Text
, Edit1.Text
will not change.
Binding.Bind(Edit1,'Text',Edit2,'Text',[mwboTwoWay]);
Two way binding. If you change either Edit1
or Edit2
's Text
property, the other will also be changed.
Or, you can do it at design-time by setting the Edit1.Text
property to:
{Edit2.Text, twoWay:true}
And then call Binding.AutoBind(Self)
in the Form's OnCreate
event handler.
kbmMW SmartBinding is included in kbmMW Community Edition for Delphi 10.4 Sydney, which is freely available for download at https://portal.components4developers.com
CodePudding user response:
You can't link TEdit
controls together. What you need to do is when the user logs in, read the 1st TEdit
's Text
property and save it to a String
, then when the next Form is shown, assign that String
to the 2nd TEdit
's Text
property.
For example:
user: String;
...
user := Form1.UserEdit.Text;
...
Form2.UserEdit.Text := user;