DDE in Delphi 3.x

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
ChrisBerryAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

ronit051397Commented:
To what application you want to connect with DDE? another Delphi application or a non Delphi application?
0
ChrisBerryAuthor Commented:
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
ronit051397Commented:
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

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Cloud Class® Course: CompTIA Cloud+

The CompTIA Cloud+ Basic training course will teach you about cloud concepts and models, data storage, networking, and network infrastructure.

ChrisBerryAuthor Commented:
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
ronit051397Commented:
Did you try SetLink('c:\FullPath\Project2','DdeServerConv1');?
0
ChrisBerryAuthor Commented:
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
ronit051397Commented:
OK, Let me check. I'll be back within a day or two.
0
ronit051397Commented:
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
ChrisBerryAuthor Commented:
Thanks - cupar@poboxes.com
0
ronit051397Commented:
Well, did you get the mail?
0
ChrisBerryAuthor Commented:
Yes, thanks will let you know the result.
0
ChrisBerryAuthor Commented:
Did you get the mail I sent in response to your demo application.?

What do you think?
0
ronit051397Commented:
I didn't get the mail.
0
ChrisBerryAuthor Commented:
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
ronit051397Commented:
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
ChrisBerryAuthor Commented:
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
ronit051397Commented:
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
ChrisBerryAuthor Commented:
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
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Delphi

From novice to tech pro — start learning today.