Solved

How do I use DDE with Delphi 2 ?

Posted on 1997-07-13
9
1,339 Views
Last Modified: 2010-08-05
How do I send a text from a client to a server?
I can't get it to work.
Do I need both the conv and item thing?

Can you give me a source for a button on the server, that when clicked send a text line to the client, and a source for a button on the client which gets the text and puts it in an edit box?
0
Comment
Question by:xoz
  • 3
  • 3
  • 2
  • +1
9 Comments
 
LVL 5

Expert Comment

by:ronit051397
ID: 1338688
sample of dde for opening a new word document and inserting 2 lines in it, In this case Word is the server. Code for Using Delphi application as a server will be displayed soon.

uses ddeman;

procedure TForm1.Button1Click(Sender: TObject);
var
  DdeClientConv1: TDdeClientConv;
  DdeClientItem1: TDdeClientItem;
  Buf: PChar;
begin
  DdeClientConv1:=TDdeClientConv.Create(Form1);
  DdeClientItem1:=TDdeClientItem.Create(Form1);
  DDEClientItem1.DDEConv := DDEClientConv1;
  GetMem(Buf,100);
  Buf[0]:=#0;
  with DdeClientConv1 do
  begin
    ConnectMode := ddeManual;
    SetLink('WinWord','System');
    OpenLink;
    StrCat(Buf,'[FileNewDefault][Insert "Example for     dde"][InsertPara][Insert "from Delphi"]');
    ExecuteMacro(Buf,False);
    CloseLink;
  end;
  FreeMem(Buf,100);
  DDEClientItem1.Free;
  DdeClientConv1.Free;
end;


0
 

Author Comment

by:xoz
ID: 1338689
Thanks.

I'm waiting for an example of a Dephi application as a server.
How should I use the SetLink then ?
How do I pass text and not a macro?

BTW: Are you from Israel? Me too...

0
 
LVL 5

Expert Comment

by:ronit051397
ID: 1338690
Yes I am.
To pass a text use pokedata. You will get the answer for the server tomorrow.
0
Does Powershell have you tied up in knots?

Managing Active Directory does not always have to be complicated.  If you are spending more time trying instead of doing, then it's time to look at something else. For nearly 20 years, AD admins around the world have used one tool for day-to-day AD management: Hyena. Discover why

 

Author Comment

by:xoz
ID: 1338691
This is my client's source:
------------------------

procedure TForm1.Button1Click(Sender: TObject);
begin
     DDEClientItem1.DDEConv := DDEClientConv1;
     with DdeClientConv1 do
     begin
          ConnectMode := ddeManual;
          DdeService := 'ddesproj';
          ServiceApplication := 'ddesproj';
          DdeTopic := 'DDEServerConv1';
          if SetLink('ddesproj','DDEServerConv1') then
             MessageDlg('Link Established.', mtInformation, [mbOK],0);
          OpenLink;
     end;
end;

procedure TForm1.Button2Click(Sender: TObject);
begin
     Edit1.Text:=DdeClientItem1.Text;
end;

procedure TForm1.Button3Click(Sender: TObject);
begin
     DdeClientConv1.CloseLink;
end;

procedure TForm1.DdeClientItem1Change(Sender: TObject);
begin
  Edit1.Text:=DdeClientItem1.Text;
end;


This is my server's source:
--------------------------
procedure TForm1.Button1Click(Sender: TObject);
begin
     DdeServerItem1.ServerConv := DdeServerConv1;
     DdeServerItem1.Text := 'abcde';
end;

When I run the client and press button1 the link is established, and if the server is not
running, the client runs it.

Then I press button1 on the server, and expect the edit1.text in the client to change,
becuase of the DdeClientItem1Change procedure, but it doesn't.
If I try pressing button2 on the client edit1.text just turns empty...

Maybe my problem has to do with DdeclientItem1.DdeItem what should I set it to ?
The help is very unclear about it.

Thanks,

Yogev ascalar@netvision.net.il
0
 
LVL 5

Accepted Solution

by:
ronit051397 earned 100 total points
ID: 1338692
Didn't look much at your source code. Try the following Example which 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.
0
 

Author Comment

by:xoz
ID: 1338693
Thanks, I'll try it now.

I wanted to send text from the server to client, I'll try to chnage your code to do so.

I've got Delphi 2, there's no demo example for the DDE there, and the documentation and help about the DDE is very bad.

0
 
LVL 1

Expert Comment

by:ygolan
ID: 1338694
Hey, that makes us 3 Israelis on Delphi experts list...
0
 
LVL 2

Expert Comment

by:amateur83
ID: 25066845
pro...thanks for sharing this..
0
 
LVL 2

Expert Comment

by:amateur83
ID: 25066848
can i transfer a TObject or TRecord to there?
0

Featured Post

PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

Question has a verified solution.

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

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…
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…
This Micro Tutorial demonstrates using Microsoft Excel pivot tables, how to reverse engineer competitors' marketing strategies through backlinks.
Microsoft Active Directory, the widely used IT infrastructure, is known for its high risk of credential theft. The best way to test your Active Directory’s vulnerabilities to pass-the-ticket, pass-the-hash, privilege escalation, and malware attacks …

770 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