PostCommand(Command: String; [Argument: Variant = Null]);
Command. Name of the command that will be sent to the form.
Argument. Command argument.
The PostCommand method enables sending a command to a form.
Commands are processed in the Form.OnCommand event.
NOTE. This method is executed after all commands in the individual procedure.
Executing the example requires two forms:
A form with the SOURCEFORM identifier with the Button1 button on it.
A form with the DESTINATIONFORM identifier with the Label1 component on it.
Add a link to the DESTINATIONFORM form in the assembly inspector in the SOURCEFORM form. Add the Public access modifier for the DESTINATIONFORM form class and to the descriptions of the Label1 component.
Add the OnClick event handler for the Button1 button with the following code:
Class SOURCEFORMForm: Form
Button1: Button;
Sub Button1OnClick(Sender: Object; Args: IMouseEventArgs);
Var
DestForm: DESTINATIONFORMForm;
Begin
DestForm := New DESTINATIONFORMForm.CreateForm;
DestForm.PostCommand("ChangeLabel", "LastName");
DestForm.Label1.Text := "NewName";
DestForm.Visible := True;
End Sub Button1OnClick;
End Class SOURCEFORMForm;
Add the OnCommand event handler for the DESTINATIONFORM form with the following code:
Public Class DESTINATIONFORMForm: Form
Public Label1: Label;
Sub DESTINATIONFORMFormOnCommand(Sender: Object; Args: ICommandEventArgs);
Begin
If Args.Command = "ChangeLabel" Then
Label1.Text := Args.Argument As String;
End If;
End Sub DESTINATIONFORMFormOnCommand;
End Class DESTINATIONFORMForm;
Clicking the Button1 button creates an instance of the DESTINATIONFORM form and the ChangeLabel command with the LastName argumnet is sent to it. This command should rename the text of the Label1 component into LastName. The next line changes the Label1 text for NewName, but because of the PostCommand method execution after all the rest commands, the Label1 component text will be equal to LastName.
See also: