Solved

DDE in Delphi1.0

Posted on 1997-06-09
12
355 Views
Last Modified: 2010-04-06
I have a DDE app that works fine in D2 & D3. I am trying to run pretty much the same app in D1 for my WFW clients but the DDE client only get 255 characters back from the DDE server even though I am using DdeClientItem.Lines instead of DdeClientItem.Text. It is as if the ".Lines" property has a bug that makes it act just like the ".Text" property.
Of course, the identical code works fine in NT with D2 or D3 !
0
Comment
Question by:kupiec
  • 7
  • 5
12 Comments
 
LVL 1

Accepted Solution

by:
slp earned 100 total points
ID: 1336887
The Lines property should behave more or less like an array of 255 character strings, and you generally have to treat it as such if you want to get at all of the text:

for i := 0 to DDEClientItem1.Lines.Count - 1 do
begin
  DoSomethingTo( DDEClientItem1.Lines[i] ) ;
end ;

Now, depending on what you want to do, you might be better served by accessing the whole block using the Lines.GetText property and treating it as a PChar.


0
 

Author Comment

by:kupiec
ID: 1336888
This is exactly what I am doing. That is the point ! The Lines property is not behaving like Lines, but like Text ( 255 character limit ).

Here is some of the code: (keep in mind that in Delphi2 under NT this works exactly as written!)

    ParseEdit: TEdit;
    workArea: TMemo;
    String3270: TStringGrid;
    getSOfar,charPTR,getLIMIT: Integer;

  workArea.Lines := DdeClientItem.Lines;
  workArea.SelectAll;
  workArea.CopyToClipBoard;
  ParseEdit.PasteFromClipBoard;
  SyncStr := Copy(ParseEdit.Text, 1, 80);
  while (getSOfar <= getLIMIT) do
    begin
       SyncStr := Copy(ParseEdit.Text, charPTR, 80);
        begin
         with String3270 do
            for L := 0 to 0 do
               for M:= getSOfar to getSOfar do
                  Cells[L,M] := SyncStr;
         Inc(getSOfar);
         charPTR := charPTR + 80;
        end;
    end;

0
 
LVL 1

Expert Comment

by:slp
ID: 1336889
> This is exactly what I am doing. That is the point ! The Lines
> property is not behaving like Lines, but like Text ( 255
> character limit ).

> Here is some of the code: (keep in mind that in Delphi2 under
> NT this works exactly as written!

Forgive me for presuming to reformat your code, but I was having trouble seeing what was going on:

> ParseEdit: TEdit;
> workArea: TMemo;
> String3270: TStringGrid;
> getSOfar,charPTR,getLIMIT: Integer;

> workArea.Lines := DdeClientItem.Lines;
> workArea.SelectAll;
> workArea.CopyToClipBoard;
> ParseEdit.PasteFromClipBoard;

I think THIS may be your problem right here; under D1 the .Text
property of a TEdit is limited to 255 characters (uses a short string, there is no "long" string in D1).  What is the purpose of the clipboard copy?  Why not work with workArea.Lines (or DDEClientItem.Lines for that matter) directly?

> SyncStr := Copy(ParseEdit.Text, 1, 80);
> while (getSOfar <= getLIMIT) do
>   begin
>     SyncStr := Copy(ParseEdit.Text, charPTR, 80);
>     begin
>       with String3270 do

This won't get you very far, is this a typographical error? :

>         for L := 0 to 0 do
>           for M:= getSOfar to getSOfar do
>             Cells[L,M] := SyncStr;
>       Inc(getSOfar);
>       charPTR := charPTR + 80;
>     end;
>   end;

Okay, so if I'm reading this right, what you're trying to do is populate the stringgrid with 80 character blocks from the DDEClientItem?  You probably won't be able to do that in D1 by treating the Lines property as an array of strings, because you won't be able to take a solely character by character view of it; I'd recommend copying the contents of DDEClientItem into a PChar buffer and working with it like that; something like:

var
  DDEBuffer, ShortBuff, charPtr : PChar ;
  SyncStr : string[80] ;
  Len, chars : word ;
begin
  Len := StrLen( DDEClientItem.GetText ) ;
  GetMem( DDEBuffer, Len ) ;
  GetMem( ShortBuff, 80 ) ;
  StrCopy( DDEBuffer, DDEClientItem.GetText ) ;
  charPtr := Buffer ;  
  chars := 0 ;
  while ( getSoFar <= getLimit ) and ( chars <= Len ) do
  begin
    StrLCopy( ShortBuff, charPtr, 80 ) ;
    chars := chars + StrLen( ShortBuff ) ;
    SyncStr:= StrPas( ShortBuff ) ;
   
  {work out for yourself which cell you want to copy SyncStr to}
       
    Inc( charPtr, 80 ) ;
  end ;
  FreeMem( DDEBuffer, Len ) ;
  FreeMem( ShortBuff, 80 ) ;


0
Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

 
LVL 1

Expert Comment

by:slp
ID: 1336890
Oooops, the line that reads:

charPtr := Buffer ;

in my code snippet should read:

charPtr := DDEBuffer ;
0
 

Author Comment

by:kupiec
ID: 1336891
Thanks for the quick response !
I'll try this today.
FYI:
This won't get you very far, is this a typographical error? :
                  > for L := 0 to 0 do
                  > for M:= getSOfar to getSOfar do  

No, there is a larger loop:
   while (getSOfar <= getLIMIT) do begin...
which moves me down my grid. I always want column to be zero because there is only one column (lot's of rows, but only one column.
0
 

Author Comment

by:kupiec
ID: 1336892
Here is a problem with your solution:

-->> DDEClientItem.GetText

DDEClientItem has NO GetText Property !
This is one of the reasons I do all the finagling with TMemo and TEdit and ClipBoard.
0
 

Author Comment

by:kupiec
ID: 1336893
Here is the problem with your solution:

-->> DDEClientItem.GetText

DDEClientItem has NO GetText Property !
This is one of the reasons I do all the finagling with TMemo and TEdit and ClipBoard.

Looks like I'm back to SQUARE.ONE.
0
 

Author Comment

by:kupiec
ID: 1336894
-->> DDEClientItem.GetText

DDEClientItem.Lines.GetText compiles cleanly, but now I get garbage instead of merely 255 characters ! I keep pressing on...
seems just around the corner.
0
 

Author Comment

by:kupiec
ID: 1336895
Found my "garbage" problem. But, I'm still afflicted. Guess what the following returns:

  Len := StrLen( DDEClientItem.Lines.GetText ) ;
  ShowStr := IntToStr(Len);
  ShowMessage(ShowStr);

If you guessed 257, you win !
Problem is, it should be around 1920 ( the DDE server is a 3270 terminal emulator ).

I just compiled this UNCHANGED in D2, and it returns 1922 ! (as well as filling my grid with ALL the lines !!!!

Hey, you can have the 100 points ! I don't think this one is going to go away. Smells like something funky in the D1 DdeClientItem to me.
b.
0
 
LVL 1

Expert Comment

by:slp
ID: 1336896
> DDEClientItem.Lines.GetText compiles cleanly, but now I get
> garbage instead of merely 255 characters ! I keep pressing
> on... seems just around the corner.

Ooops, my error again, definitely need the "Lines" property specifier.  

> Found my "garbage" problem. But, I'm still afflicted. Guess
> what the following returns:
>
>  Len := StrLen( DDEClientItem.Lines.GetText ) ;
>  ShowStr := IntToStr(Len);
>  ShowMessage(ShowStr);
>
> If you guessed 257, you win ! Problem is, it should be around
> 1920 ( the DDE server is a 3270 terminal emulator ).

This is weird, the only other thing that occurrs to me is to wonder if there are embedded nulls (#0) in the text which makes the PChar terminate; but then it shouldn't work in D2 either.  Are you running the D1 version under Win95 or Win3.1?  

Thanks for the points, I don't feel like I've really earned them yet, do you want to continue this investigation (via Email perhaps?).
0
 

Author Comment

by:kupiec
ID: 1336897
->Are you running the D1 version under Win95 or Win3.1?

Have tested on two different machines, one is NT4 and the other is WFW3.1. There are no embedded nulls that I can detect. Moreover, the D2 version "pages" through multiple 3270 screens and concatenates them into the client's string grid (one of the reasons for the nested loop). It never barks at any of the data.

I will keep pecking at this because I need to resolve it for my WFW clients, and would be quite willing to exchange email.
0
 
LVL 1

Expert Comment

by:slp
ID: 1336898
Okay, you can contact me at slposey@concentric.net.  If you like send me the exact offending code so I can see everything in context.  I will gladly submit to any non-disclosure agreements you may require.  In the meantime I will have a look at the implementation of the TDDEClientItem.Lines property and see if there's anything glaringly wrong.
0

Featured Post

Free Tool: Postgres Monitoring System

A PHP and Perl based system to collect and display usage statistics from PostgreSQL databases.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Machine not responding during CopyFile() 3 103
Convert Jpg /PNG To GIF 5 150
Convert a string into a TDateTime 5 63
Delphi problems to abort a printjob 9 24
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…
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…
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…
In an interesting question (https://www.experts-exchange.com/questions/29008360/) here at Experts Exchange, a member asked how to split a single image into multiple images. The primary usage for this is to place many photographs on a flatbed scanner…

839 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