Link to home
Start Free TrialLog in
Avatar of kupiec
kupiec

asked on

DDE in Delphi1.0

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 !
ASKER CERTIFIED SOLUTION
Avatar of slp
slp

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of kupiec
kupiec

ASKER

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;

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


Oooops, the line that reads:

charPtr := Buffer ;

in my code snippet should read:

charPtr := DDEBuffer ;
Avatar of kupiec

ASKER

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.
Avatar of kupiec

ASKER

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.
Avatar of kupiec

ASKER

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.
Avatar of kupiec

ASKER

-->> 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.
Avatar of kupiec

ASKER

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.
> 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?).
Avatar of kupiec

ASKER

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