Reputation: 572
I'm writing a touchscreen enabled application in Delphi XE2.
I have a form with TEdits
. When I click on them, I call the procedure I've written to show another maximized always on top form with a TTouchkeyboard
with a label (for caption) and a TEdit
for keyboard input.
My procedure (vkeyboard
is my form name with the TTouchkeyboard
):
procedure TLogin.showkeyboard(numeric,password: Boolean;
caption,value:string;Sender:TObject);
begin
if numeric then
vkeyboard.TouchKeyboard1.Layout := 'NumPad' // make the TTouchkeyboard on the form numeric or alpha
else
vkeyboard.TouchKeyboard1.Layout := 'Standard';
if password then
vkeyboard.input.PasswordChar := '*' //make the TEdit show * or normal characters
else
vkeyboard.input.PasswordChar := #0;
vkeyboard.title.Caption := caption;
vkeyboard.input.Text := value;
vkeyboard.Show;
end;
I'm trying to send Form1.Edit1
object to the form vkeyboard
but i don't know how to do it properly!
Why? Because i want to be able to click Done on the input form (vkeyboard
) then trace back who was the sender then update the text in the main form edit!
procedure Tvkeyboard.sButton1Click(Sender: TObject);
begin
(temp as TEdit).Text := input.Text; // send back the text to the right object
vkeyboard.Hide;
end;
This little part of course didn't work... I think i need to specified that the temp object belong the X form ?
To be clear, i want to trace back who called the procedure or at least be able to specified it in the procedure and then return back the text (from the 2nd form to the main one) to the right TEdit
!
Upvotes: 1
Views: 1935
Reputation: 163357
You're welcome to pass whatever arguments you want to whatever function you want. If you need to use the passed value in yet another function, you'll need to save it somewhere so the later function can still access it.
Using your example, you appear to have provided a Sender
parameter for your showkeyboard
function. I assume that's where you're passing a reference to the TEdit
control that triggered the keyboard to show. The Tvkeyboard
object stored in vkeyboard
will need to use that value later, so give a copy of that value to the Tvkeyboard
object. Declare a TEdit
field:
type
Tvkeyboard = class(...)
...
public
EditSender: TEdit;
Then, in showkeyboard
, set that field:
vkeyboard.EditSender := Sender;
Finally, use that field when you set the text:
procedure Tvkeyboard.sButton1Click(Sender: TObject);
begin
EditSender.Text := input.Text; // send back the text to the right object
Self.Hide;
end;
Since you know it will always be a TEdit
control, you can change the type of the Sender
parameter in showkeyboard
to reflect that specific type:
procedure TLogin.showkeyboard(..., Sender: TEdit);
Upvotes: 4