Solved

Indy components - Converting D5 to D6

Posted on 2007-11-20
10
739 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
Migrating Your Company's PCs

To keep pace with competitors, businesses must keep employees productive, and that means providing them with the latest technology. This document provides the tips and tricks you need to help you migrate an outdated PC fleet to new desktops, laptops, and tablets.

 
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

Does Powershell have you tied up in knots?

Managing Active Directory does not always have to be complicated.  If you are spending more time trying instead of doing, then it's time to look at something else. For nearly 20 years, AD admins around the world have used one tool for day-to-day AD management: Hyena. Discover why

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
TVirtualStringTree  search using TEdit 7 121
can't find the executable in Simulator 1 90
When i run adoquery my application freezes 26 166
Graphics32 under Delphi 10.1 Berlin 2 67
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…
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…
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.

810 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