Solved

Indy components - Converting D5 to D6

Posted on 2007-11-20
10
737 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
Comment Utility
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
Comment Utility
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
Comment Utility
>> 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
 
LVL 17

Accepted Solution

by:
TheRealLoki earned 75 total points
Comment Utility
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
Highfive Gives IT Their Time Back

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

 

Author Comment

by:Softtech
Comment Utility
>> 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
Comment Utility
>> 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
Comment Utility
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
Comment Utility
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
Comment Utility
well, that's debugging for you isn't it? a different problem each day
0

Featured Post

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

In this tutorial I will show you how to use the Windows Speech API in Delphi. I will only cover basic functions such as text to speech and controlling the speed of the speech. SAPI Installation First you need to install the SAPI type library, th…
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…
Get a first impression of how PRTG looks and learn how it works.   This video is a short introduction to PRTG, as an initial overview or as a quick start for new PRTG users.
Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…

762 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