Solved

Indy components - Converting D5 to D6

Posted on 2007-11-20
10
745 Views
Last Modified: 2013-11-23
I have a Delphi 5 project that uses the Indy TidHTTP component.  I recently tried opening the D5 project in Delphi 6.  Evidently Indy has changed many things between D5 and D6.  My code now no longer runs in D6.  The part I'm stuck on is the use of a TStream instead of a TStringList.  Here's the old D5 code:

var
  lst: TStringList;
begin
   lst := TStringList.Create;
   with lst do
   try
     Values[Address2.Name] := Address2.Text;
     Values[Address1.Name] := Address1.Text;
     Values[City.Name] := City.Text;
     Values[State.Name] := State.Text;
     Memo1.Text := IdHTTP1.Post(Edit1.Text,  lst);
   finally
     lst.Free;
   end;

The problem again is that the .Post method expects a TStream instead of a TStringList.  Unfortunately, I don't know how to convert the code from strings to a stream.  Can someone assist?  Thanks.
0
Comment
Question by:Softtech
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
  • 3
  • 2
10 Comments
 
LVL 25

Expert Comment

by:imitchie
ID: 20325657
can you have a look at the method header options, there should be multiple Post(... ) functions. I recall there is one for string
0
 
LVL 17

Expert Comment

by:TheRealLoki
ID: 20325725
Post() is overlaoded, you can still post a string
fwif, in case you really need to do it as a stream, here is 1 way to do so :-


var
  lst: TStringList;
  ss: TStringStream;
  s: string;
begin
   lst := TStringList.Create;
   ss := TStringStream.Create('');
   with lst do
   try
     Values[Address2.Name] := Address2.Text;
     Values[Address1.Name] := Address1.Text;
     Values[City.Name] := City.Text;
     Values[State.Name] := State.Text;
     s := lst.text;
     ss.WriteString(s);
     ss.seek(0, soFromBeginning);
     Memo1.Text := IdHTTP1.Post(Edit1.Text, ss);
   finally
     lst.Free;
     ss.free;
   end;

Open in new window

0
 

Author Comment

by:Softtech
ID: 20330319
>> Post() is overlaoded, you can still post a string

Even with YOUR code example, the D6 compiler states, "There is no overloaded version of 'Post' that can be called with these arguments."
0
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 17

Accepted Solution

by:
TheRealLoki earned 75 total points
ID: 20330573
My code works fine with with Indy 9...

Indy 10 uses TIdStream (TIdStreamVCL)
and that would be called as

uses IDStreamVCL;

    var
        AStream: TIDStreamVCL;
..
        AStream := TIDStreamVCL.Create(TStringStream.Create(''), True);
        try
...
        IdHTTP1.Post(Edit1.Text, AStream);
...
        finally
            FreeAndNil(AStream);
        end;


Can you tell us what version of INDY YOU have installed in D6
(right click on the component and choose "about")
0
 

Author Comment

by:Softtech
ID: 20330627
>> Can you tell us what version of INDY YOU have installed in D6

The version that came with Delphi 6:  i.e., 8.0.25
0
 

Author Comment

by:Softtech
ID: 20330638
>> uses IDStreamVCL;

There is no such unit with Delphi 6 and Indy 8.0.25
0
 
LVL 25

Assisted Solution

by:imitchie
imitchie earned 75 total points
ID: 20331011
finally got to a computer with Delphi 6

    procedure Post(URL: string; const Source: TStrings; const AResponseContent:
      TStream);
      overload;
    procedure Post(URL: string; const Source, AResponseContent: TStream);
      overload;

this is from Delphi7

function TIdCustomHTTP.Post(AURL: string; const ASource: TStrings): string;
var
  LResponse: TStringStream;
begin
  LResponse := TStringStream.Create('');
  try
    Post(AURL, ASource, LResponse);
  finally
    result := LResponse.DataString;
    LResponse.Free;
  end;
end;

so modify your code
var
  lst: TStringList;
  LResponse: TStringStream;
begin
   LResponse := TStringStream.Create('');
   try
   lst := TStringList.Create;
   with lst do
   try
     Values[Address2.Name] := Address2.Text;
     Values[Address1.Name] := Address1.Text;
     Values[City.Name] := City.Text;
     Values[State.Name] := State.Text;
     IdHTTP1.Post(Edit1.Text,  lst, LResponse);
     Memo1.Text := LResponse.DataString;
   finally
     lst.Free;
   end;
   finally
     LResponse.Free;
   end;

Open in new window

0
 

Author Comment

by:Softtech
ID: 20331396
Well, your 21 lines of code compile just fine.  The problem is, the address/city/state strings never get to the web page form.  I do get a response back from the server, but the response basically tells me that the form never received the data I was trying to pass to it.

Something is broken in this conversion attempt.
0
 
LVL 25

Expert Comment

by:imitchie
ID: 20332049
well, that's debugging for you isn't it? a different problem each day
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

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…
Introduction Raise your hands if you were as upset with FireMonkey as I was when I discovered that there was no TListview.  I use TListView in almost all of my applications I've written, and I was not going to compromise by resorting to TStringGrid…
There are cases when e.g. an IT administrator wants to have full access and view into selected mailboxes on Exchange server, directly from his own email account in Outlook or Outlook Web Access. This proves useful when for example administrator want…
Michael from AdRem Software outlines event notifications and Automatic Corrective Actions in network monitoring. Automatic Corrective Actions are scripts, which can automatically run upon discovery of a certain undesirable condition in your network.…
Suggested Courses
Course of the Month11 days, 3 hours left to enroll

632 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