How can I open files directly from the internet?
I tried
memo1.lines.loadfromfile('but that doesn't work.
I tried
memo1.lines.loadfromfile('but that doesn't work.
Follow along with the video below to see how to install our site as a web app on your home screen.
Note: This feature may not be available in some browsers.
uses WinInet;
// ...
function getInternetFile( aURL : string;
aStream : tStream ) : Boolean;
const
BUF_SIZE = 1024;
OPEN_TYP = INTERNET_OPEN_TYPE_PRECONFIG;
var
hiSession,
hiConnect : hInternet;
achBuffer : array[ 0 .. BUF_SIZE ] of char;
cardCount : cardinal;
begin
result := FALSE; // assume failure
hiSession := internetOpen(nil, OPEN_TYP, nil, nil, 0);
try
hiConnect :=
internetOpenURL( hiSession, pChar( aURL ), nil, 0, 0, 0 );
try
while TRUE do
begin
if not internetReadFile( hiConnect,
@achBuffer, sizeOf( achBuffer ),
cardCount ) then break;
if cardCount = 0 then break
else
begin
aStream.write( achBuffer, cardCount );
result := TRUE;
end; // else
end; // while
finally
internetCloseHandle( hiConnect );
end; // try/finally
finally
internetCloseHandle( hiSession );
end; // try/finally
end;
procedure TForm1.Button1Click(Sender: TObject);
var
msFetch : TMemoryStream;
begin
listbox1.Items.Clear;
memo1.lines.clear;
msFetch := tMemoryStream.create;
screen.cursor := crHourglass;
try
if getInternetFile( edit1.text, msFetch ) then
begin
msFetch.position := 0;
Memo1.Lines.loadFromStream( msFetch );
end
else
Memo1.Lines.Text := 'Unable to fetch ' + edit1.text;
finally;
msFetch.free;
screen.cursor := crDefault;
end; // try/finally
end;