gyno
gyno

Reputation: 1

Using Localhost in Delphi

Evening everyone,

The ideology was given yesterday so, i have been taking my time to learn delphi. I want to send data vis URL (using GET request / Wininet) now i have problems using the http://localhost in delphi program, as when i try to use the localhost like this http://localhost, it comments the other instructions to be concatenated

I am using Lazarus , and my code goes like this

program InfoWininet;

{$mode delphi}{$H+}

uses
  {$IFDEF UNIX}{$IFDEF UseCThreads}
  cthreads,
  {$ENDIF}{$ENDIF}
  Classes , Windows , Wininet
  { you can add units after this };

var
  FirstName : string;
  LastName: string;
  Email: string ;
  IDNumber: string;
  IOpen, IURL: HINTERNET;
  Read: Cardinal;
  data: string;
  Result : string;
  http : HINTERNET;

begin
    Writeln('Enter Your First Name: ');
    Readln(FirstName);
    Writeln('Enter your Last Name: ');
    Readln(LastName);
    Writeln('Enter Your Email: ');
    Readln(Email);
    Writeln('Enter your ID Number: ');
    Readln(IDNumber);

    data := http://localhost/data.php?fname=' + FirstName + '&lastName=' + LastName + '&Email=' + Email +  '&IdNumber=' + IDNumber;
   begin
    Result:='';
    try
     IOpen := InternetOpen('Oxysys',INTERNET_OPEN_TYPE_PRECONFIG, '', '',INTERNET_FLAG_NEED_FILE);
      if IOpen<>nil then
        try
        IURL:= InternetOpenUrl(IOpen, data, nil, 0,INTERNET_FLAG_DONT_CACHE, 0);
    if IURL<> nil then
        try
          SetLength(data,4096);
        repeat
    if InternetReadFile(IURL,@data[1],4096,Read) then
    Result:=Result + Copy(data,1,Read)
        else
        Break;
    until Read = 0;
    finally
      InternetCloseHandle(IURL);
    end;
    finally
      InternetCloseHandle(IOpen);
        end;
          except
    end;
          Writeln('Message Sent Successfully...');
          Readln;
end;
end.

Question is i get the following errors, when trying to compile my program

InfoWininet.lpr(33,13) Warning: Variable "http" does not seem to be initialized
InfoWininet.lpr(33,13) Error: Incompatible types: got "Pointer" expected "AnsiString"
InfoWininet.lpr(33,17) Fatal: Syntax error, ";" expected but ":" found

What could really be the problem? Can someone pls help, in correcting the problem, pls Am trying to learn Delphi Very well.

Upvotes: 0

Views: 742

Answers (1)

David Heffernan
David Heffernan

Reputation: 612954

data := http://localhost/data.php?fname=' + FirstName + '&lastName=' + LastName + 
  '&Email=' + Email +  '&IdNumber=' + IDNumber;

You have failed to wrap your string literal in quotes. It should be:

data := 'http://localhost/data.php?fname=' + ....
        ^
    quote missing here

Upvotes: 1

Related Questions