Solved

DDE in Delphi1.0

Posted on 1997-06-09
12
351 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
Comment Utility
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
Comment Utility
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
Comment Utility
> 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
 
LVL 1

Expert Comment

by:slp
Comment Utility
Oooops, the line that reads:

charPtr := Buffer ;

in my code snippet should read:

charPtr := DDEBuffer ;
0
 

Author Comment

by:kupiec
Comment Utility
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
Comment Utility
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
Maximize Your Threat Intelligence Reporting

Reporting is one of the most important and least talked about aspects of a world-class threat intelligence program. Here’s how to do it right.

 

Author Comment

by:kupiec
Comment Utility
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
Comment Utility
-->> 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
Comment Utility
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
Comment Utility
> 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
Comment Utility
->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
Comment Utility
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

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

Suggested Solutions

In this tutorial I will show you how to use the Windows Speech API in Delphi. I will only cover basic functions such as text to speech and controlling the speed of the speech. SAPI Installation First you need to install the SAPI type library, th…
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…
This video discusses moving either the default database or any database to a new volume.
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…

728 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

9 Experts available now in Live!

Get 1:1 Help Now