Solved

DDE in Delphi 3.x

Posted on 1998-01-12
18
475 Views
Last Modified: 2010-05-18
Has anyone got the DDE components to work correctly in Delphi 3.x, specifically:-

1) Connecting to an application not in the same directory.
2) Getting the Server Item name to stay in the ClientItem.DDEItem

Are there any other components available that work and if so where?

Thanks for any assistance.

Chris
0
Comment
Question by:ChrisBerry
  • 9
  • 9
18 Comments
 
LVL 5

Expert Comment

by:ronit051397
ID: 1356196
To what application you want to connect with DDE? another Delphi application or a non Delphi application?
0
 

Author Comment

by:ChrisBerry
ID: 1356197
I have two Delphi applications both of which must be client and server as I wish to pass messages between both. Also I do not want the client to have to request/poll for messages but to be told - OnChange - when a message has arrived for it.
0
 
LVL 5

Accepted Solution

by:
ronit051397 earned 50 total points
ID: 1356198
Use the following Example which works, and try to figure out how DDE works:

On this example when you press a button on a client application,
then the contents of the edit box in this client application are shown in an edit box in the server application.

1. Create a project and call it Project1 (the client application).
2. Create a button and an edit box.
3. write the following code:
procedure TForm1.Button1Click(Sender: TObject);
var
  DdeClientConv1: TDdeClientConv;
  DdeClientItem1: TDdeClientItem;
  Buf: PChar;
begin                           DdeClientConv1:=TDdeClientConv.Create(Form1);                           DdeClientItem1:=TDdeClientItem.Create(Form1);
  DdeClientItem1.DdeItem := 'DdeServerItem1';
  DDEClientItem1.DDEConv := DDEClientConv1;
  GetMem(Buf,100);
  with DdeClientConv1 do
  begin
    ConnectMode := ddeManual;
    SetLink('Project2','DdeServerConv1');
    OpenLink;
    StrPCopy(Buf, Edit1.Text);
    ExecuteMacro(Buf,True);
    CloseLink;
  end;
  FreeMem(Buf,100);
  DDEClientItem1.Free;
  DdeClientConv1.Free;
end;

4. Create a project on the same directory as project1 and call it Project2 (the server application).
5. Create a TDdeServerConv with the name DdeServerConv1.
6. Create a TDdeServerItem with the name DdeServerItem1.
7. Set DdeServerItem1.ServerConv to DdeServerConv1.
8. Create an edit box.
9. write the following code on the OnExecuteMacro Event:
procedure Tform1.DdeServerConv1ExecuteMacro(Sender: TObject;
       Msg: TStrings);
begin
  Edit1.Text:=Msg[0];
end;

10. First run project2 then run project1.
11. Press the button on project1. The contents of the edit box in the client will be shown on the edit box in the server.
12. If this doesn't work, then let me Know.
13. I use exeutemacro because it is more stable then pokedata and doesn't create access violations.
14. There is an example in the demos directory in Delphi1.

If you want both applications to be clients and servers then do the same in the other application.
0
 

Author Comment

by:ChrisBerry
ID: 1356199
Sorry for the delay in replying.

Thanks for your reply, however I am looking to use the DDE using the full path, as it states the component will do, but I still am unable to connect although the application does open, an instance for every SetLink. If I have both apps in the same directory all is OK.
0
 
LVL 5

Expert Comment

by:ronit051397
ID: 1356200
Did you try SetLink('c:\FullPath\Project2','DdeServerConv1');?
0
 

Author Comment

by:ChrisBerry
ID: 1356201
Yes I did and as I said it launched the application but would not connect. I tried the same on an application that worked in the same directory using the project name but when I changed to the full path it would not work.??!!??

Using the project name it always used the same instance, using the full path it always launched a new instance.

0
 
LVL 5

Expert Comment

by:ronit051397
ID: 1356202
OK, Let me check. I'll be back within a day or two.
0
 
LVL 5

Expert Comment

by:ronit051397
ID: 1356203
Ok, I checked, and this is working also when 2 projects are in different directories. Post your EMail address so I can send you the examples.
0
 

Author Comment

by:ChrisBerry
ID: 1356204
Thanks - cupar@poboxes.com
0
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
LVL 5

Expert Comment

by:ronit051397
ID: 1356205
Well, did you get the mail?
0
 

Author Comment

by:ChrisBerry
ID: 1356206
Yes, thanks will let you know the result.
0
 

Author Comment

by:ChrisBerry
ID: 1356207
Did you get the mail I sent in response to your demo application.?

What do you think?
0
 
LVL 5

Expert Comment

by:ronit051397
ID: 1356208
I didn't get the mail.
0
 

Author Comment

by:ChrisBerry
ID: 1356209
This is a copy of the mail sent 22/1/98:-

Hi,

Thanks for your help so far.

Don't know if I should reply via e-mail or Experts Exchange but here
goes.

> Attached 2 sample projects. Place them in 2 different directories
> and let me know.

1) If I have both the Client and Server running they work fine.

2) If I run the Client it will not instansiate the Server either from
separate diectories or if I put the EXEs in the same diectory.

3) I modified the code to include the full path in the Client
SetLink. This had the effect of running a different instance of
the Server for every key press but did not transfer any data.

These are the same problems as I have been having although I was not
using the Macro path for the transfer of data.

Where to from here? Do you get the same problems or is it something
to do with my system?

Regards

0
 
LVL 5

Expert Comment

by:ronit051397
ID: 1356210
In order to get it work properly, you need to open both client and server, and then do what ever you need. Is it necessary for you to open the server automatically when the client call it?
0
 

Author Comment

by:ChrisBerry
ID: 1356211
I did want to open the server from the client. The documentation states that it will do this and in fact it will but does not connect. It also opens a new instance of the server every time you try to connect, not what I want.
0
 
LVL 5

Expert Comment

by:ronit051397
ID: 1356212
Yes, there is a problem with that. I suggest you open the server not by DDE, but by any other method, say, calling winexec for example, and then, start talking to it by DDE.
0
 

Author Comment

by:ChrisBerry
ID: 1356213
I guess we might as well call a halt on this. Your last answer is where I was at the begining, ie I implemented it that way, but I have since changed to using WM_Copydata which seems to be more reliable than the DDE components.

Thanks for your help
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Objective: - This article will help user in how to convert their numeric value become words. How to use 1. You can copy this code in your Unit as function 2. than you can perform your function by type this code The Code   (CODE) The Im…
In this tutorial I will show you how to use the Windows Speech API in Delphi. I will only cover basic functions such as text to speech and controlling the speed of the speech. SAPI Installation First you need to install the SAPI type library, th…
Video by: Mark
This lesson goes over how to construct ordered and unordered lists and how to create hyperlinks.
Both in life and business – not all partnerships are created equal. As the demand for cloud services increases, so do the number of self-proclaimed cloud partners. Asking the right questions up front in the partnership, will enable both parties …

911 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

19 Experts available now in Live!

Get 1:1 Help Now