程序代码:
************************************************** *-- Form: form1 (d:\documents\visual foxpro 项目\server.scx) *-- ParentClass: form *-- BaseClass: form *-- Time Stamp: 01/01/23 11:16:01 PM * DEFINE CLASS form1 AS form Top = 0 Left = 0 Height = 629 Width = 851 DoCreate = .T. Caption = "Server" Name = "Form1" ADD OBJECT olecontrol1 AS olecontrol WITH ; Top = 0, ; Left = 820, ; Height = 100, ; Width = 100, ; Visible = .F., ; Name = "Olecontrol1" ADD OBJECT edit1 AS editbox WITH ; Height = 420, ; Left = 0, ; ReadOnly = .T., ; Top = 0, ; Width = 570, ; Name = "Edit1" ADD OBJECT edit2 AS editbox WITH ; Height = 208, ; Left = 0, ; Top = 421, ; Width = 770, ; Name = "Edit2" ADD OBJECT command2 AS commandbutton WITH ; Top = 570, ; Left = 780, ; Height = 50, ; Width = 60, ; Caption = "\<Send", ; Name = "Command2" PROCEDURE Init *!* Set the LocalPort property to an integer. *!* Then invoke the Listen method. this.olecontrol1.object.LocalPort=1001 this.olecontrol1.object.Listen() *!* frmClient.Show ' Show the client form. DO FORM client *!* this.lostfocus() *!* _screen.Forms(2).gotfocus() ENDPROC PROCEDURE olecontrol1.Error *** ActiveX 控件事件 *** LPARAMETERS number, description, scode, source, helpfile, helpcontext, canceldisplay ENDPROC PROCEDURE olecontrol1.DataArrival *** ActiveX 控件事件 *** LPARAMETERS bytestotal *!* (ByVal bytesTotal As Long) *!* Declare a variable for the incoming data. *!* Invoke the GetData method and set the Text *!* property of a TextBox named txtOutput to *!* the data. *!* Dim strData As String LOCAL strdata strdata=REPLICATE(CHR(0),255) thisform.olecontrol1.object.getdata(@strdata) thisform.edit1.value =thisform.edit1.value+TRANSFORM(DATE())+" "+TRANSFORM(TIME())+CHR(13)+"Client:" thisform.edit1.value =thisform.edit1.value+strData ENDPROC PROCEDURE olecontrol1.ConnectionRequest *** ActiveX 控件事件 *** LPARAMETERS requestid *!* Private Sub thisform.olecontrol1.object_ConnectionRequest _ *!* (ByVal requestID As Long) *!* Check if the control's State is closed. If not, *!* close the connection before accepting the new *!* connection. If thisform.olecontrol1.object.State <> 0 thisform.olecontrol1.object.Close *!* Accept the request with the requestID *!* parameter. thisform.olecontrol1.object.Accept(requestID) ENDIF ENDPROC PROCEDURE olecontrol1.Accept *** ActiveX 控件方法程序 *** LPARAMETERS requestid ENDPROC PROCEDURE edit2.KeyPress LPARAMETERS nKeyCode, nShiftAltCtrl IF nkeycode=10 &&AND nshiftaltctrl=2 &&Ctrl+Enter () ENDIF ENDPROC PROCEDURE command2.Click *!* The TextBox control named txtSendData *!* contains the data to be sent. Whenever the user *!* types into the textbox, the string is sent *!* using the SendData method. IF !EMPTY(thisform.edit2.value) thisform.edit1.Value=thisform.edit1.Value+TRANSFORM(DATE())+" "+TRANSFORM(TIME())+CHR(13)+"Me:" thisform.edit1.Value=thisform.edit1.Value+thisform.edit2.Value+CHR(13) thisform.olecontrol1.object.SendData(thisform.edit2.value+CHR(13)) thisform.edit2.Value="" ENDIF ENDPROC ENDDEFINE * *-- EndDefine: form1 **************************************************