forked from Kromster80/kam_remake
-
Notifications
You must be signed in to change notification settings - Fork 0
/
KM_HTTPClient.pas
76 lines (56 loc) · 1.54 KB
/
KM_HTTPClient.pas
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
64
65
66
67
68
69
70
71
72
73
74
75
unit KM_HTTPClient;
{$I KaM_Remake.inc}
interface
uses
Classes, SysUtils
{$IFDEF WDC} ,KM_HTTPClientOverbyte {$ENDIF}
{$IFDEF FPC} ,KM_HTTPClientLNet {$ENDIF};
type
//General wrapper for Delphi/Lazarus implementations
TKMHTTPClient = class
private
{$IFDEF WDC} fClient: TKMHTTPClientOverbyte; {$ENDIF}
{$IFDEF FPC} fClient: TKMHTTPClientLNet; {$ENDIF}
fOnError: TGetStrProc;
fOnReceive: TGetStrProc;
procedure Error(const S: string);
procedure GetCompleted(const S: string);
public
constructor Create;
destructor Destroy; override;
procedure GetURL(aURL: string; aIsUTF8: Boolean);
procedure UpdateStateIdle;
property OnError: TGetStrProc write fOnError;
property OnReceive: TGetStrProc write fOnReceive;
end;
implementation
constructor TKMHTTPClient.Create;
begin
inherited;
{$IFDEF WDC} fClient := TKMHTTPClientOverbyte.Create; {$ENDIF}
{$IFDEF FPC} fClient := TKMHTTPClientLNet.Create; {$ENDIF}
fClient.OnGetCompleted := GetCompleted;
fClient.OnError := Error;
end;
destructor TKMHTTPClient.Destroy;
begin
fClient.Free;
inherited;
end;
procedure TKMHTTPClient.GetURL(aURL: string; aIsUTF8: Boolean);
begin
fClient.GetURL(aUrl, aIsUTF8);
end;
procedure TKMHTTPClient.GetCompleted(const S: string);
begin
if Assigned(fOnReceive) then fOnReceive(S);
end;
procedure TKMHTTPClient.Error(const S: string);
begin
if Assigned(fOnError) then fOnError(S);
end;
procedure TKMHTTPClient.UpdateStateIdle;
begin
{$IFDEF FPC} fClient.UpdateStateIdle; {$ENDIF}
end;
end.