Solved

Indy components - Converting D5 to D6

Posted on 2007-11-20
10
741 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

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

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…
Hello everybody This Article will show you how to validate number with TEdit control, What's the TEdit control? TEdit is a standard Windows edit control on a form, it allows to user to write, read and copy/paste single line of text. Usua…
A short tutorial showing how to set up an email signature in Outlook on the Web (previously known as OWA). For free email signatures designs, visit https://www.mail-signatures.com/articles/signature-templates/?sts=6651 If you want to manage em…
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa…

710 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