DDESetTopic( ) Function

Creates or releases a topic name from a service name in a dynamic data exchange (DDE) conversation.

DDESetTopic(cServiceName, cTopicName [, cUDFName])

Return Values

Logical

Parameters

  • cServiceName
    Specifies the service name. Additional service names can be created with DDESetService( ).

  • cTopicName
    Specifies the topic name to create or release. If you include cUDFName, DDESetTopic( ) creates the topic name cTopicName. If you omit cUDFName, the topic name cTopicName is released. If cTopicName is an empty string, the user-defined function specified with cUDFName is executed for any topic name that isn't explicitly declared.

  • cUDFName
    Specifies the name of the user-defined function executed when a client application makes a request to the topic name. If you omit cUDFName, the topic name cTopicName is released from the service name.

    When the user-defined function is executed, it is passed the following six parameters in the order given below:

    Parameter Contents
    Channel Number The client channel number.
    Action ADVISE, EXECUTE, INITIATE, POKE, REQUEST, or TERMINATE.
    Item The item name; for example, R1C1 for a Microsoft Excel worksheet cell.
    Data Data from the client.
    Format The data format; for example, CF_TEXT.
    Advise Status The link type (0 = manual, 2 = notify or automatic).

    The values of the Item, Data, and Advise Status parameters depend on the Action parameter. The following table lists the Action parameter values and the values contained in the Item, Data, and Advise Status parameters. A dash (–) indicates that the parameter value is the empty string.

    Action value Item value Data value Advise status
    INITIATE Topic name
    TERMINATE
    POKE Item name New data
    REQUEST Item name
    EXECUTE New command
    ADVISE Item name Link type

    If the user-defined function successfully handles the client request, the user-defined function should return true (.T.). If the request can't be handled or an error occurs, the user-defined function should return false (.F.). If false is returned when the Action parameter value is INITIATE, the client topic name request is rejected. If false is returned when the value is POKE, REQUEST, or EXECUTE, the request is ignored. If false is returned when the value is ADVISE, the client request for a notify or automatic link is rejected.

Remarks

After a topic name is created, any client requests to the topic name cause Visual FoxPro to execute the user-defined function specified with cUDFName. The user-defined function is passed a set of parameters whose values are determined by the client request. The user-defined function return value is passed to the client with DDEPoke( ). The return value is a logical value indicating whether the topic name can provide the service requested by the client.

DDESetTopic( ) returns true (.T.) if it successfully creates or releases the topic name. It returns false (.F.) if the topic name cannot be created or released. Use DDELastError( ) to determine why a topic name cannot be created or released.

Example

The following example creates a basic sample server called myserver that supports Visual FoxPro command execution from a client application. The client application makes requests to myserver through the DO topic, and macro substitution is used to execute the client's command.

** Set Visual FoxPro up as a DDE server ** = DDESetService('myserver', 'DEFINE') = DDESetService('myserver', 'EXECUTE', .T.) = DDESetTopic('myserver', 'DO', 'DOTOPIC') WAIT WINDOW 'Server portion service setup ... ' NOWAIT ** Use Visual FoxPro as a DDE client ** gnChannel = DDEInitiate('myserver','DO') =DDEExecute(gnChannel, 'WAIT WINDOW "Command Executed ... "') =DDETerminate(gnChannel) PROCEDURE dotopic PARAMETERS gnChannel, gcAction, gcItem, gData, gcFormat, gnAdvise glResult = .F. ** It's necessary to return .T. from an ** ** INITIATE action or no connection is made ** IF gcAction = 'INITIATE' glResult = .T. ENDIF IF gcAction = 'EXECUTE' &gData glResult = .T. ENDIF IF gcAction = 'TERMINATE' WAIT WINDOW 'Goodbye ... ' NOWAIT glResult = .T. ENDIF RETURN glResult

After running this example program, you have set up Visual FoxPro service, which other applications can access. If you have Microsoft Excel, you can run the following Excel macro:

gnMyChan = INITIATE("myserver","DO")
=EXECUTE(MyChan,"WAIT WINDOW 'Hi, this is EXCEL speaking'")
=RETURN( )

See Also

DDEEnabled( ) | DDELastError( ) | DDEPoke( ) | DDESetService( )