Solved

DDE in Delphi 3.x

Posted on 1998-01-12
18
499 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

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
 
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

On Demand Webinar - Networking for the Cloud Era

This webinar discusses:
-Common barriers companies experience when moving to the cloud
-How SD-WAN changes the way we look at networks
-Best practices customers should employ moving forward with cloud migration
-What happens behind the scenes of SteelConnect’s one-click button

Question has a verified solution.

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

Suggested Solutions

Hello everybody This Article will show you how to validate number with TEdit control, What's the TEdit control? TEdit is a standard Windows edit control on a form, it allows to user to write, read and copy/paste single line of text. Usua…
Introduction I have seen many questions in this Delphi topic area where queries in threads are needed or suggested. I know bumped into a similar need. This article will address some of the concepts when dealing with a multithreaded delphi database…
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa…
In a recent question (https://www.experts-exchange.com/questions/29004105/Run-AutoHotkey-script-directly-from-Notepad.html) here at Experts Exchange, a member asked how to run an AutoHotkey script (.AHK) directly from Notepad++ (aka NPP). This video…

737 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