- phpx_src.zip
- C# Example
- Help
- JavaScript Example
- php4Delphi.dll
- PHPXControl.ocx
|
using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;
namespace PHPXApp
{
/// <summary>
/// Summary description for Form1.
/// </summary>
public class Form1 : System.Windows.Forms.Form
{
private System.Windows.Forms.Button btnSimple;
private System.Windows.Forms.Button btnVariables;
private System.Windows.Forms.TextBox txtVariable;
/// <summary>
/// Required designer variable.
/// </summary>
private System.ComponentModel.Container components = null;
private System.Windows.Forms.Button btnCallback;
private System.Windows.Forms.TextBox txtDLLFolder;
private System.Windows.Forms.Label label1;
PHPXControl.PHPX php = new PHPXControl.PHPXClass();
public Form1()
{
//
// Required for Windows Form Designer support
//
InitializeComponent();
// This is the directory that PHP4TS.DLL or PHP5TS.DLL resides in
php.HandleErrors = true;
php.HTMLErrors = false;
php.OnFunctionExecute += new PHPXControl.IPHPXEvents_OnFunctionExecuteEventHandler(php_OnFunctionExecute);
}
/// <summary>
/// Clean up any resources being used.
/// </summary>
protected override void Dispose( bool disposing )
{
php.FinalizeControl();
if( disposing )
{
if (components != null)
{
components.Dispose();
}
}
base.Dispose( disposing );
}
#region Windows Form Designer generated code
/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeComponent()
{
this.btnSimple = new System.Windows.Forms.Button();
this.btnVariables = new System.Windows.Forms.Button();
this.txtVariable = new System.Windows.Forms.TextBox();
this.btnCallback = new System.Windows.Forms.Button();
this.txtDLLFolder = new System.Windows.Forms.TextBox();
this.label1 = new System.Windows.Forms.Label();
this.SuspendLayout();
//
// btnSimple
//
this.btnSimple.Location = new System.Drawing.Point(8, 48);
this.btnSimple.Name = "btnSimple";
this.btnSimple.Size = new System.Drawing.Size(176, 23);
this.btnSimple.TabIndex = 0;
this.btnSimple.Text = "Simple Example";
this.btnSimple.Click += new System.EventHandler(this.btnSimple_Click);
//
// btnVariables
//
this.btnVariables.Location = new System.Drawing.Point(8, 80);
this.btnVariables.Name = "btnVariables";
this.btnVariables.Size = new System.Drawing.Size(176, 23);
this.btnVariables.TabIndex = 1;
this.btnVariables.Text = "Variable Example";
this.btnVariables.Click += new System.EventHandler(this.btnVariables_Click);
//
// txtVariable
//
this.txtVariable.Location = new System.Drawing.Point(192, 80);
this.txtVariable.Name = "txtVariable";
this.txtVariable.TabIndex = 2;
this.txtVariable.Text = "User";
//
// btnCallback
//
this.btnCallback.Location = new System.Drawing.Point(8, 112);
this.btnCallback.Name = "btnCallback";
this.btnCallback.Size = new System.Drawing.Size(176, 23);
this.btnCallback.TabIndex = 3;
this.btnCallback.Text = "CallBack Example";
this.btnCallback.Click += new System.EventHandler(this.btnCallback_Click);
//
// txtDLLFolder
//
this.txtDLLFolder.Location = new System.Drawing.Point(96, 16);
this.txtDLLFolder.Name = "txtDLLFolder";
this.txtDLLFolder.Size = new System.Drawing.Size(200, 20);
this.txtDLLFolder.TabIndex = 4;
this.txtDLLFolder.Text = "h:\\PHPX\\";
//
// label1
//
this.label1.Location = new System.Drawing.Point(8, 16);
this.label1.Name = "label1";
this.label1.Size = new System.Drawing.Size(80, 23);
this.label1.TabIndex = 5;
this.label1.Text = "DLL Directory";
//
// Form1
//
this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);
this.ClientSize = new System.Drawing.Size(328, 150);
this.Controls.Add(this.label1);
this.Controls.Add(this.txtDLLFolder);
this.Controls.Add(this.btnCallback);
this.Controls.Add(this.txtVariable);
this.Controls.Add(this.btnVariables);
this.Controls.Add(this.btnSimple);
this.Name = "Form1";
this.Text = "PHP Test Form";
this.ResumeLayout(false);
}
#endregion
/// <summary>
/// The main entry point for the application.
/// </summary>
[STAThread]
static void Main()
{
Application.Run(new Form1());
}
private void btnSimple_Click(object sender, System.EventArgs e)
{
php.DLLFolder = txtDLLFolder.Text;
string result = php.RunCode("print \"Hello World!\"");
System.Windows.Forms.MessageBox.Show(result);
}
private void btnVariables_Click(object sender, System.EventArgs e)
{
php.DLLFolder = txtDLLFolder.Text;
php.AddVariable("user",txtVariable.Text);
string result = php.RunCode("print \"Hello $user from PHP!\"");
System.Windows.Forms.MessageBox.Show(result);
}
private void btnCallback_Click(object sender, System.EventArgs e)
{
php.DLLFolder = txtDLLFolder.Text;
php.AddFunction("test", 0);
string result = php.RunCode("print test();");
System.Windows.Forms.MessageBox.Show(result);
}
private void php_OnFunctionExecute(string FunctionName, string Parameters, ref string ReturnValue)
{
if (FunctionName=="test")
{
ReturnValue = "Hello World From C#!";
}
}
}
}
|
By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.
If a file you wish to view isn't highlighted, and is a text file (not binary), please
let us know and we'll add colourisation support for it.
Raised by wolves in the mean streets of Macintosh C/C++ for IBM and Motorola, moved on to Delphi and now C#. Ah, the mother's milk of Microsoft...