-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathtiswinhttpini.pas
More file actions
63 lines (53 loc) · 1.34 KB
/
tiswinhttpini.pas
File metadata and controls
63 lines (53 loc) · 1.34 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
unit tiswinhttpini;
{$mode delphi}
{$h+}
interface
uses
Classes,SysUtils,IniFiles;
type
TUrlIniFile = Class(TMemIniFile)
public
{$ifdef windows}
constructor Create(const URL: string);
{$endif}
end;
{$ifdef windows}
//Create a Tmemorystream or a Tfilestream with the content of the result of http URL or file location
// if the file exist (url is a local file location of type p:\bin\truc.jpg), then a filestream is created and returned in stream
// else the http protocol is used and a memorystream is returned
// IMPORTANT : stream should be freed by the caller after use !
function httpNewStream(url:String):TStream;
{$endif}
implementation
uses FileUtil,tiswinhttp;
{ TUrlIniFile }
{$ifdef windows}
constructor TURLIniFile.Create(const URL: string);
var
St:TStringList;
begin
inherited Create('');
St:=TStringList.Create;
try
St.Text:=httpGetString(URL);
SetStrings(St);
finally
St.Free;
end;
end;
Function httpNewStream(url:String):TStream;
var
content:String;
begin
if not FileExists(URL) then
begin
result:=TMemoryStream.Create;
Content:=httpGetString(url);
Result.Write(Content[1],Length(Content));
result.Seek(0,soFromBeginning);
end
else
result:=TFileStream.Create(URL,fmOpenRead,fmShareDenyNone);
end;
{$endif}
end.