* * *

Author Topic: Which FPC or Lazarus unit contains xmlhttprequest object?  (Read 4112 times)

vfclists

  • Hero Member
  • *****
  • Posts: 823
    • HowTos Considered Harmful?
Which FPC or Lazarus unit contains xmlhttprequest object?
« on: April 01, 2012, 08:01:03 pm »
I want to run a  Delphi program which uses msmxl for IXMLHTTPRequest and I need the Lazarus unit which implements the same. Which unit contains it? I can see XMLHTTPRequest on this forum but I can't find it when I search the sources.

/vfclistsGUY
« Last Edit: April 01, 2012, 08:08:33 pm by vfclists »
Windows - Lazarus 1.0.8/FPC 2.6.0
Linux - Lazarus 1.4.4 /FPC 2.6.4

ludob

  • Hero Member
  • *****
  • Posts: 1173
Re: Which FPC or Lazarus unit contains xmlhttprequest object?
« Reply #1 on: April 02, 2012, 11:13:49 am »
msxml is a com object. You can import the msxml.tlb type library with importtl.exe which is available in fpc 2.6.1 or 2.7.1 (both from svn repository). The import will result in a unit that contains all interface and coclass declarations for the com object, including IXMLHTTPRequest. 
I guess your Delphi program does the same and uses a unit called msxml_tlb or something similar.

The alternative is to use it with "late binding":
Code: [Select]
procedure TForm1.Button1Click(Sender: TObject);
var XMLHTTPReq:OleVariant;
begin
  XMLHTTPReq:=CreateOleObject('MSXML2.XMLHTTP.6.0');
  XMLHTTPReq.open('GET', 'http://192.168.2.105/array.xml', false);
  XMLHTTPReq.send();
  Memo1.Lines.Add(XMLHTTPReq.responseText);
end;

vfclists

  • Hero Member
  • *****
  • Posts: 823
    • HowTos Considered Harmful?
Re: Which FPC or Lazarus unit contains xmlhttprequest object?
« Reply #2 on: April 03, 2012, 01:36:13 am »
When I look at the code it seems to serve a role that can be performed by other web related libraries and it needs to be cross platform. Is there something in fpweb that might perform this role?

msxml is a com object. You can import the msxml.tlb type library with importtl.exe which is available in fpc 2.6.1 or 2.7.1 (both from svn repository). The import will result in a unit that contains all interface and coclass declarations for the com object, including IXMLHTTPRequest. 
I guess your Delphi program does the same and uses a unit called msxml_tlb or something similar.

The alternative is to use it with "late binding":
Code: [Select]
procedure TForm1.Button1Click(Sender: TObject);
var XMLHTTPReq:OleVariant;
begin
  XMLHTTPReq:=CreateOleObject('MSXML2.XMLHTTP.6.0');
  XMLHTTPReq.open('GET', 'http://192.168.2.105/array.xml', false);
  XMLHTTPReq.send();
  Memo1.Lines.Add(XMLHTTPReq.responseText);
end;
Windows - Lazarus 1.0.8/FPC 2.6.0
Linux - Lazarus 1.4.4 /FPC 2.6.4

ludob

  • Hero Member
  • *****
  • Posts: 1173
Re: Which FPC or Lazarus unit contains xmlhttprequest object?
« Reply #3 on: April 03, 2012, 09:47:50 am »
Quote
and it needs to be cross platform
Pffff.... That is the sound of my crystal ball failing again :(
Quote
I want to run a  Delphi program which uses msmxl for IXMLHTTPRequest
So much for asking the right question.

Laksen

  • Hero Member
  • *****
  • Posts: 594
    • J-Software
Re: Which FPC or Lazarus unit contains xmlhttprequest object?
« Reply #4 on: April 03, 2012, 10:32:17 am »
Just use httpsend from Synapse. It's very easy to use and crossplatform

DavidTh30

  • New member
  • *
  • Posts: 5
Re: Which FPC or Lazarus unit contains xmlhttprequest object?
« Reply #5 on: September 01, 2017, 03:43:10 am »
To use "xmlhttprequest" depends on where you use.

"Microsoft.XMLHTTP" and "MSXML2.XMLHTTP.3.0" need permission or login before send something to URL.
I use "WinHttp.WinHttpRequest.5.1" only request to getting the message.

I show you.  ;D

uses
  ...
  Variants, comobj, RegExpr;   

Function getText(strURL: variant): String;  //My testing device is "FL BT EPA" and "FL BT EPA MP" (communicate using AT language)
var
  xstrResult:variant;
  WinHttpReq:variant;
  temp:variant;
begin
  WinHttpReq:=CreateOleObject('Microsoft.XMLHTTP');
  temp:=WinHttpReq.Open('GET',strURL,false);
  try
  WinHttpReq.Send();
  xstrResult:= WinHttpReq.responseText;
  except
    showmessage('Transfer not work');
    //raise;
    Exit;
  end;

  getText:=xstrResult;
end;

Function getText3(strURL: variant): String;  //My testing device is "FL BT EPA" and "FL BT EPA MP" (communicate using AT language)
var
  XMLHTTPReq:variant;
begin
  XMLHTTPReq:=CreateOleObject('MSXML2.XMLHTTP.3.0');

  try
  XMLHTTPReq.Open('GET',strURL,false);
  except
    showmessage('access denied');
    Exit;
  end;

  try
  XMLHTTPReq.Send();
  getText3:= XMLHTTPReq.responseText;
  except
    showmessage('Transfer not work');
    Exit;
  end;
end;

Function getText2(strURL: variant): String;
var
  http :variant;
begin
  http:=createoleobject('WinHttp.WinHttpRequest.5.1');
  try
  http.open('GET', strURL, false);
  http.send;
  except
    showmessage('Transfer not work');
    Exit;
  end;
  getText2:=http.responsetext;

end;

procedure TForm1.Button1Click(Sender: TObject);
var
  re: TRegExpr;
  strAns:String;
begin
  re := TRegExpr.Create;
  re.Expression := '.*OK.*';
  strAns:=getText('http://10.0.0.100/form?at=at*amli=admin');
  if re.Exec(strAns) then showmessage('OK') else showmessage('not OK');
end;

procedure TForm1.Button2Click(Sender: TObject);
var
  strAns:String;
begin
  strAns:=getText2('http://lazarus.freepascal.org');
  Showmessage(strAns);
end;

procedure TForm1.Button3Click(Sender: TObject);
var
  strAns:String;
begin
  strAns:=getText3('http://10.0.0.100/form?at=at*amli=admin');
  Showmessage(strAns);
end;   
« Last Edit: September 01, 2017, 03:45:06 am by DavidTh30 »

 

Recent

Get Lazarus at SourceForge.net. Fast, secure and Free Open Source software downloads Open Hub project report for Lazarus