Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Indy components - Converting D5 to D6

Posted on 2007-11-20
10
Medium Priority
?
766 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
  • 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
Industry Leaders: 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 225 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 225 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

Keep up with what's happening at Experts Exchange!

Sign up to receive Decoded, a new monthly digest with product updates, feature release info, continuing education opportunities, and more.

Question has a verified solution.

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

Objective: - This article will help user in how to convert their numeric value become words. How to use 1. You can copy this code in your Unit as function 2. than you can perform your function by type this code The Code   (CODE) The Im…
Creating an auto free TStringList The TStringList is a basic and frequently used object in Delphi. On many occasions, you may want to create a temporary list, process some items in the list and be done with the list. In such cases, you have to…
This course is ideal for IT System Administrators working with VMware vSphere and its associated products in their company infrastructure. This course teaches you how to install and maintain this virtualization technology to store data, prevent vuln…
This lesson discusses how to use a Mainform + Subforms in Microsoft Access to find and enter data for payments on orders. The sample data comes from a custom shop that builds and sells movable storage structures that are delivered to your property. …
Suggested Courses

916 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