Link to home
Start Free TrialLog in
Avatar of Gwena
Gwena

asked on

I need help with Fpiettes THttpCli .....

I was using some other freeware web components... but they were buggy so I'm switching over to Fpiettes stuff... but I'm having some trouble handling the data... here is the code I'm playing with


unit HttpGet1;

interface

uses
  WinTypes, WinProcs, Messages, SysUtils, Classes, Graphics, Controls, Forms,
  Dialogs, HttpProt, StdCtrls, UrlLabel, Sock;

type
  THttpGetForm = class(TForm)
    GetButton: TButton;
    AbortButton: TButton;
    InfoLabel: TLabel;
    HttpCli1: THttpCli;
    procedure GetButtonClick(Sender: TObject);
    procedure HttpCli1DocData(Sender: TObject; Buffer: Pointer;
      Len: Integer);
    procedure HttpCli1HeaderData(Sender: TObject);
    procedure AbortButtonClick(Sender: TObject);
  private

  public

  end;

var
  HttpGetForm: THttpGetForm;
  MyArray : Array[1..1000] of byte;

implementation

{$R *.DFM}


procedure THttpGetForm.GetButtonClick(Sender: TObject);
begin
    HttpCli1.URL        := ' http://www.gurlpages.com/computer/gwena/atest.txt';
    HttpCli1.Proxy      := '';
    HttpCli1.ProxyPort  := '80';
    HttpCli1.RcvdStream := TFileStream.Create('c:\windows\temp\atest.txt', fmCreate);
    GetButton.Enabled   := FALSE;
    AbortButton.Enabled := TRUE;
    InfoLabel.Caption   := 'Loading';
    try
        try
            HttpCli1.Get;
            InfoLabel.Caption := IntToStr(HttpCli1.RcvdStream.Size) ;
        except
            on E: EHttpException do begin
                InfoLabel.Caption := 'Failed : ' +
                                     IntToStr(HttpCli1.StatusCode) + ' ' +
                                     HttpCli1.ReasonPhrase;;
            end
            else
                raise;
        end;
    finally
        GetButton.Enabled   := TRUE;
        AbortButton.Enabled := FALSE;
        HttpCli1.RcvdStream.Destroy;
        HttpCli1.RcvdStream := nil;
    end;
end;



procedure THttpGetForm.HttpCli1DocData(Sender: TObject; Buffer: Pointer;
  Len: Integer);
begin
    InfoLabel.Caption := IntToStr(HttpCli1.RcvdCount);
end;



procedure THttpGetForm.HttpCli1HeaderData(Sender: TObject);
begin
    InfoLabel.Caption := InfoLabel.Caption + '.';
end;



procedure THttpGetForm.AbortButtonClick(Sender: TObject);
begin
    HttpCli1.Abort;
end;




end.


This works VERY well... it goes to my web site and gets a tiny file 'atest.txt'  and then saves it in the windows\temp\  directory.
What I want to do is instead of getting the file and saving it on disk I just want to get it and somehow put it into the array    MyArray : Array[1..1000] of byte;  Everything I try seems to fail :(  I don't need to store the data onto the disk... the program only needs to have it in the array.... it bugs me to have to save it on disk and then read it back into myarray .... if someone can  actually change the source code above so that it places the data into the array I will add some more points :)

..Gwen..
ASKER CERTIFIED SOLUTION
Avatar of Madshi
Madshi

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Gwena
Gwena

ASKER

Hi Madshi :)

It stops on this line

 Move(HttpCli1.RcvdStream.Memory^, pointer(str)^,


and says  'Undeclared Identifier: 'Memory'.

I sure hope this can be made to work :)


If this ends up working will I be limited to the size of
a regular string (255) for my file? Or can I easily use
an AnsiString type?  How much data could an ansi string
hold...... jeez I sound pretty clueless huh ;-)
RcvdStream is a generic TStream.  You may have to typecast it to get to the Memory property.

try:

Move((HttpCli1.RcvdStream as TMemoryStream).Memory^, pointer(str)^, Length(str));


Avatar of Gwena

ASKER

Hi there scrapdog!

That really helped!
Thank heavens you showed up... I was about to pull my hair out ;-)

I have got to find a really really GOOD book and learn more about streams and pointers..... this Delphi Developers Guide
weighs at least 10lbs... but has only a casual mention of these
2 topics :(


...Gwen..
If you want to learn about pointers, I suggest just getting a good PASCAL text.  Pointers are a part of the Pascal language...a Pascal textbook will cover them more in depth, and a Delphi text might assume you already know Pascal.

Streams (the encapsulated ones), however, are a part of Delphi, so you probably won't find these in a Pascal textbook.

By the way, does your program work as expected now, or do you need more help?
Thanx, scrappy for your assistance. I was at sleep (counting sheeps :-).

Gwen, of course you should use an ansi string. The maximal size of an ansi string is about 2 GB...   :-)

Regards, Madshi.
Avatar of Gwena

ASKER

Hi scrapdog :)

"By the way, does your program work as expected now, or do you need more help?"

---> 'needs-help' is my middle name ;-)

The program does seem to work ok now .... I am going to
have to send you a few points for your help in fixing up
madshi's code for me .....I was wanting this code so
I would have an easy way to make any program I write
able to get a data file from my website... for update announcements, patches, ...or whatever.


I will get out the box full of books on Turbo Pascal and
see if I can get some info on streams.. It never occured to me that those old Pascal books might help... thanx
The sheep were running away from the wolf.

And you are just the person to kill it:

https://www.experts-exchange.com/jsp/qShow.jsp?ta=delphi&qid=10236103 

You have gotten me out of more than one graphical jam, so thanks in advance. =)

>I will get out the box full of books
>on Turbo Pascal and
>see if I can get some info on
>streams.. It never occured to me that
>those old Pascal books might help...
>thanx

Nope, you won't find streams in a TP book, except for 'input', 'output', and files.  There aren't any built-in encapsulated stream types.  You need a Delphi text for this stuff. =(

However, you will probably find a lot about using pointers, etc.

Hint:  you can also find get a lot of Pascal specific help at https://www.experts-exchange.com/comp/lang/pascal/   

[ "my" board...hehe =) ]
Avatar of Gwena

ASKER

>[ "my" board...hehe =) ]

Wow scrapdog!  You are 'Top Dog' over on that group :-)
hehe, makes up for my low Delphi score =)
scrapdog, the suggestion with the low priority thread on your mouseMove questions sounds good to me. If that is still not good enough, you could forget about WM_MOUSEMOVE and poll the mouse position with GetCursor in a thread. But I don't like polling. If you get WM_MOUSEMOVE to work fast enough, that would be much better...
thanks for your input
Avatar of Gwena

ASKER

Adjusted points to 75
Avatar of Gwena

ASKER

Thanks Madshi!  as always you have been a great help to me :)
You're welcome! Thanx for the point boost...   :-)