Solved

DDE in Delphi1.0

Posted on 1997-06-09
12
354 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
Courses: Start Training Online With Pros, Today

Brush up on the basics or master the advanced techniques required to earn essential industry certifications, with Courses. Enroll in a course and start learning today. Training topics range from Android App Dev to the Xen Virtualization Platform.

 
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

Courses: Start Training Online With Pros, Today

Brush up on the basics or master the advanced techniques required to earn essential industry certifications, with Courses. Enroll in a course and start learning today. Training topics range from Android App Dev to the Xen Virtualization Platform.

Question has a verified solution.

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

Introduction The parallel port is a very commonly known port, it was widely used to connect a printer to the PC, if you look at the back of your computer, for those who don't have newer computers, there will be a port with 25 pins and a small print…
Have you ever had your Delphi form/application just hanging while waiting for data to load? This is the article to read if you want to learn some things about adding threads for data loading in the background. First, I'll setup a general applica…
Two types of users will appreciate AOMEI Backupper Pro: 1 - Those with PCIe drives (and haven't found cloning software that works on them). 2 - Those who want a fast clone of their boot drive (no re-boots needed) and it can clone your drive wh…
This video shows how to use Hyena, from SystemTools Software, to bulk import 100 user accounts from an external text file. View in 1080p for best video quality.

816 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

10 Experts available now in Live!

Get 1:1 Help Now