Solved

DDE in Delphi 3.x

Posted on 1998-01-12
18
469 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
What Security Threats Are You Missing?

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

 
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

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

The uses clause is one of those things that just tends to grow and grow. Most of the time this is in the main form, as it's from this form that all others are called. If you have a big application (including many forms), the uses clause in the in…
This article explains how to create forms/units independent of other forms/units object names in a delphi project. Have you ever created a form for user input in a Delphi project and then had the need to have that same form in a other Delphi proj…
Sending a Secure fax is easy with eFax Corporate (http://www.enterprise.efax.com). First, Just open a new email message.  In the To field, type your recipient's fax number @efaxsend.com. You can even send a secure international fax — just include t…
Illustrator's Shape Builder tool will let you combine shapes visually and interactively. This video shows the Mac version, but the tool works the same way in Windows. To follow along with this video, you can draw your own shapes or download the file…

760 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

18 Experts available now in Live!

Get 1:1 Help Now