Rev 13 | Only display areas with differences | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 13 | Rev 18 | ||
---|---|---|---|
1 | library CurConv; |
1 | library CurConv; |
2 | 2 | ||
3 | uses |
3 | uses |
4 | SysUtils, |
4 | SysUtils, |
5 | Classes, |
5 | Classes, |
6 | Windows, |
6 | Windows, |
7 | Dialogs, |
7 | Dialogs, |
8 | Controls, |
- | |
9 | uLkJSON in '..\RTL\uLkJSON.pas', |
8 | uLkJSON in '..\RTL\uLkJSON.pas', |
10 | VtsCurConv in '..\RTL\VtsCurConv.pas'; |
9 | VtsCurConv in '..\RTL\VtsCurConv.pas'; |
11 | 10 | ||
12 | {$R *.res} |
11 | {$R *.res} |
13 | 12 | ||
14 | type |
13 | type |
15 | TVtsCurConvFlags = type DWORD; |
14 | TVtsCurConvFlags = type DWORD; |
16 | 15 | ||
17 | const |
16 | const |
18 | CONVERT_DONT_SHOW_ERRORS: TVtsCurConvFlags = 1; |
17 | CONVERT_DONT_SHOW_ERRORS: TVtsCurConvFlags = 1; |
19 | CONVERT_FALLBACK_TO_CACHE: TVtsCurConvFlags = 2; |
18 | CONVERT_FALLBACK_TO_CACHE: TVtsCurConvFlags = 2; |
20 | CONVERT_USE_SSL: TVtsCurConvFlags = 4; |
19 | CONVERT_USE_SSL: TVtsCurConvFlags = 4; |
21 | CONVERT_CONFIRM_WEB_ACCESS: TVtsCurConvFlags = 8; |
20 | CONVERT_CONFIRM_WEB_ACCESS: TVtsCurConvFlags = 8; |
22 | CONVERT_NO_INTERACTIVE_API_KEY_INPUT: TVtsCurConvFlags = 16; |
21 | CONVERT_NO_INTERACTIVE_API_KEY_INPUT: TVtsCurConvFlags = 16; |
23 | 22 | ||
24 | const |
23 | const |
25 | S_VTSCONV_OK: HRESULT = $20000000; // Success, Customer defined, Facility 0, Code 0 |
24 | S_VTSCONV_OK: HRESULT = $20000000; // Success, Customer defined, Facility 0, Code 0 |
26 | S_VTSCONV_NOTHING: HRESULT = $20000001; // Success, Customer defined, Facility 0, Code 1 |
25 | S_VTSCONV_NOTHING: HRESULT = $20000001; // Success, Customer defined, Facility 0, Code 1 |
27 | E_VTSCONV_GENERIC_FAILURE: HRESULT = $A0000000; // Failure, Customer defined, Facility 0, Code 0 |
26 | E_VTSCONV_GENERIC_FAILURE: HRESULT = $A0000000; // Failure, Customer defined, Facility 0, Code 0 |
28 | E_VTSCONV_BAD_ARGS: HRESULT = $A0000001; // Failure, Customer defined, Facility 0, Code 1 |
27 | E_VTSCONV_BAD_ARGS: HRESULT = $A0000001; // Failure, Customer defined, Facility 0, Code 1 |
29 | E_VTSCONV_STOREDKEY_INVALID: HRESULT = $A0000002; // Failure, Customer defined, Facility 0, Code 2 |
28 | E_VTSCONV_STOREDKEY_INVALID: HRESULT = $A0000002; // Failure, Customer defined, Facility 0, Code 2 |
30 | E_VTSCONV_NO_STOREDKEY: HRESULT = $A0000003; // Failure, Customer defined, Facility 0, Code 3 |
29 | E_VTSCONV_NO_STOREDKEY: HRESULT = $A0000003; // Failure, Customer defined, Facility 0, Code 3 |
31 | 30 | ||
32 | function DeleteAPIKey(UserMode: BOOL; DontShowErrors: BOOL): HRESULT; stdcall; |
31 | function DeleteAPIKey(UserMode: BOOL; DontShowErrors: BOOL): HRESULT; stdcall; |
33 | begin |
32 | begin |
34 | try |
33 | try |
35 | if TVtsCurConv.DeleteAPIKey(UserMode) then |
34 | if TVtsCurConv.DeleteAPIKey(UserMode) then |
36 | result := S_VTSCONV_OK |
35 | result := S_VTSCONV_OK |
37 | else |
36 | else |
38 | result := S_VTSCONV_NOTHING; |
37 | result := S_VTSCONV_NOTHING; |
39 | except |
38 | except |
40 | on E: Exception do |
39 | on E: Exception do |
41 | begin |
40 | begin |
42 | if DontShowErrors then MessageDlg(e.Message, mtError, [mbOk], 0); |
41 | if DontShowErrors then MessageDlg(e.Message, mtError, [mbOk], 0); |
43 | result := E_VTSCONV_GENERIC_FAILURE; |
42 | result := E_VTSCONV_GENERIC_FAILURE; |
44 | end; |
43 | end; |
45 | end; |
44 | end; |
46 | end; |
45 | end; |
47 | 46 | ||
48 | function WriteAPIKeyW(key: LPCWSTR; UserMode: BOOL; DontShowErrors: BOOL): HRESULT; stdcall; |
47 | function WriteAPIKeyW(key: LPCWSTR; UserMode: BOOL; DontShowErrors: BOOL): HRESULT; stdcall; |
49 | begin |
48 | begin |
50 | try |
49 | try |
51 | if Length(key) <> 32 then |
50 | if Length(key) <> 32 then |
52 | begin |
51 | begin |
53 | result := E_VTSCONV_BAD_ARGS; |
52 | result := E_VTSCONV_BAD_ARGS; |
54 | Exit; |
53 | Exit; |
55 | end; |
54 | end; |
56 | TVtsCurConv.WriteAPIKey(TVtsCurApiKey(key), UserMode); |
55 | TVtsCurConv.WriteAPIKey(TVtsCurApiKey(key), UserMode); |
57 | result := S_VTSCONV_OK; |
56 | result := S_VTSCONV_OK; |
58 | except |
57 | except |
59 | on E: Exception do |
58 | on E: Exception do |
60 | begin |
59 | begin |
61 | if DontShowErrors then MessageDlg(e.Message, mtError, [mbOk], 0); |
60 | if DontShowErrors then MessageDlg(e.Message, mtError, [mbOk], 0); |
62 | result := E_VTSCONV_GENERIC_FAILURE; |
61 | result := E_VTSCONV_GENERIC_FAILURE; |
63 | end; |
62 | end; |
64 | end; |
63 | end; |
65 | end; |
64 | end; |
66 | 65 | ||
67 | function WriteAPIKeyA(key: LPCSTR; UserMode: BOOL; DontShowErrors: BOOL): HRESULT; stdcall; |
66 | function WriteAPIKeyA(key: LPCSTR; UserMode: BOOL; DontShowErrors: BOOL): HRESULT; stdcall; |
68 | begin |
67 | begin |
69 | try |
68 | try |
70 | if Length(key) <> 32 then |
69 | if Length(key) <> 32 then |
71 | begin |
70 | begin |
72 | result := E_VTSCONV_BAD_ARGS; |
71 | result := E_VTSCONV_BAD_ARGS; |
73 | Exit; |
72 | Exit; |
74 | end; |
73 | end; |
75 | TVtsCurConv.WriteAPIKey(TVtsCurApiKey(key), UserMode); |
74 | TVtsCurConv.WriteAPIKey(TVtsCurApiKey(key), UserMode); |
76 | result := S_VTSCONV_OK; |
75 | result := S_VTSCONV_OK; |
77 | except |
76 | except |
78 | on E: Exception do |
77 | on E: Exception do |
79 | begin |
78 | begin |
80 | if DontShowErrors then MessageDlg(e.Message, mtError, [mbOk], 0); |
79 | if DontShowErrors then MessageDlg(e.Message, mtError, [mbOk], 0); |
81 | result := E_VTSCONV_GENERIC_FAILURE; |
80 | result := E_VTSCONV_GENERIC_FAILURE; |
82 | end; |
81 | end; |
83 | end; |
82 | end; |
84 | end; |
83 | end; |
85 | 84 | ||
86 | function ReadAPIKeyW(key: LPWSTR; DontShowErrors: BOOL): HRESULT; stdcall; |
85 | function ReadAPIKeyW(key: LPWSTR; DontShowErrors: BOOL): HRESULT; stdcall; |
87 | var |
86 | var |
88 | s: WideString; |
87 | s: WideString; |
89 | begin |
88 | begin |
90 | try |
89 | try |
91 | s := WideString(TVtsCurConv.ReadAPIKey); |
90 | s := WideString(TVtsCurConv.ReadAPIKey); |
92 | if s = '' then |
91 | if s = '' then |
93 | begin |
92 | begin |
94 | result := E_VTSCONV_NO_STOREDKEY; |
93 | result := E_VTSCONV_NO_STOREDKEY; |
95 | Exit; |
94 | Exit; |
96 | end; |
95 | end; |
97 | if Length(s) <> 32 then |
96 | if Length(s) <> 32 then |
98 | begin |
97 | begin |
99 | result := E_VTSCONV_STOREDKEY_INVALID; |
98 | result := E_VTSCONV_STOREDKEY_INVALID; |
100 | Exit; |
99 | Exit; |
101 | end; |
100 | end; |
102 | ZeroMemory(key, 33*SizeOf(WideChar)); |
101 | ZeroMemory(key, 33*SizeOf(WideChar)); |
103 | CopyMemory(key, @s[1], 32*SizeOf(WideChar)); |
102 | CopyMemory(key, @s[1], 32*SizeOf(WideChar)); |
104 | Result := S_VTSCONV_OK; |
103 | Result := S_VTSCONV_OK; |
105 | except |
104 | except |
106 | on E: Exception do |
105 | on E: Exception do |
107 | begin |
106 | begin |
108 | if DontShowErrors then MessageDlg(e.Message, mtError, [mbOk], 0); |
107 | if DontShowErrors then MessageDlg(e.Message, mtError, [mbOk], 0); |
109 | result := E_VTSCONV_GENERIC_FAILURE; |
108 | result := E_VTSCONV_GENERIC_FAILURE; |
110 | end; |
109 | end; |
111 | end; |
110 | end; |
112 | end; |
111 | end; |
113 | 112 | ||
114 | function ReadAPIKeyA(key: LPSTR; DontShowErrors: BOOL): HRESULT; stdcall; |
113 | function ReadAPIKeyA(key: LPSTR; DontShowErrors: BOOL): HRESULT; stdcall; |
115 | var |
114 | var |
116 | s: AnsiString; |
115 | s: AnsiString; |
117 | begin |
116 | begin |
118 | try |
117 | try |
119 | s := AnsiString(TVtsCurConv.ReadAPIKey); |
118 | s := AnsiString(TVtsCurConv.ReadAPIKey); |
120 | if s = '' then |
119 | if s = '' then |
121 | begin |
120 | begin |
122 | result := E_VTSCONV_NO_STOREDKEY; |
121 | result := E_VTSCONV_NO_STOREDKEY; |
123 | Exit; |
122 | Exit; |
124 | end; |
123 | end; |
125 | if Length(s) <> 32 then |
124 | if Length(s) <> 32 then |
126 | begin |
125 | begin |
127 | result := E_VTSCONV_STOREDKEY_INVALID; |
126 | result := E_VTSCONV_STOREDKEY_INVALID; |
128 | Exit; |
127 | Exit; |
129 | end; |
128 | end; |
130 | ZeroMemory(key, 33*SizeOf(AnsiChar)); |
129 | ZeroMemory(key, 33*SizeOf(AnsiChar)); |
131 | CopyMemory(key, @s[1], 32*SizeOf(AnsiChar)); |
130 | CopyMemory(key, @s[1], 32*SizeOf(AnsiChar)); |
132 | result := S_VTSCONV_OK; |
131 | result := S_VTSCONV_OK; |
133 | except |
132 | except |
134 | on E: Exception do |
133 | on E: Exception do |
135 | begin |
134 | begin |
136 | if DontShowErrors then MessageDlg(e.Message, mtError, [mbOk], 0); |
135 | if DontShowErrors then MessageDlg(e.Message, mtError, [mbOk], 0); |
137 | result := E_VTSCONV_GENERIC_FAILURE; |
136 | result := E_VTSCONV_GENERIC_FAILURE; |
138 | end; |
137 | end; |
139 | end; |
138 | end; |
140 | end; |
139 | end; |
141 | 140 | ||
142 | function ConvertW(Value: Double; CurFrom, CurTo: LPCWSTR; MaxAge: integer; |
141 | function ConvertW(Value: Double; CurFrom, CurTo: LPCWSTR; MaxAge: integer; |
143 | Flags: TVtsCurConvFlags; HistoricDate: TDate): Double; stdcall; |
142 | Flags: TVtsCurConvFlags; HistoricDate: TDate): Double; stdcall; |
144 | var |
143 | var |
145 | x: TVtsCurConv; |
144 | x: TVtsCurConv; |
146 | begin |
145 | begin |
147 | try |
146 | try |
148 | x := TVtsCurConv.Create; |
147 | x := TVtsCurConv.Create; |
149 | try |
148 | try |
150 | x.Secure := Flags and CONVERT_USE_SSL <> 0; |
149 | x.Secure := Flags and CONVERT_USE_SSL <> 0; |
151 | x.MaxAgeSeconds := MaxAge; |
150 | x.MaxAgeSeconds := MaxAge; |
152 | x.ConfirmWebAccess := Flags and CONVERT_CONFIRM_WEB_ACCESS <> 0; |
151 | x.ConfirmWebAccess := Flags and CONVERT_CONFIRM_WEB_ACCESS <> 0; |
153 | x.FallBackToCache := Flags and CONVERT_FALLBACK_TO_CACHE <> 0; |
152 | x.FallBackToCache := Flags and CONVERT_FALLBACK_TO_CACHE <> 0; |
154 | x.InteractiveAPIKeyInput := Flags and CONVERT_NO_INTERACTIVE_API_KEY_INPUT = 0; |
153 | x.InteractiveAPIKeyInput := Flags and CONVERT_NO_INTERACTIVE_API_KEY_INPUT = 0; |
155 | result := x.Convert(value, TVtsCur(CurFrom), TVtsCur(CurTo), HistoricDate); |
154 | result := x.Convert(value, TVtsCur(CurFrom), TVtsCur(CurTo), HistoricDate); |
156 | finally |
155 | finally |
157 | x.Free; |
156 | x.Free; |
158 | end; |
157 | end; |
159 | except |
158 | except |
160 | on E: Exception do |
159 | on E: Exception do |
161 | begin |
160 | begin |
162 | if Flags and CONVERT_DONT_SHOW_ERRORS = 0 then MessageDlg(e.Message, mtError, [mbOk], 0); |
161 | if Flags and CONVERT_DONT_SHOW_ERRORS = 0 then MessageDlg(e.Message, mtError, [mbOk], 0); |
163 | result := -1; |
162 | result := -1; |
164 | end; |
163 | end; |
165 | end; |
164 | end; |
166 | end; |
165 | end; |
167 | 166 | ||
168 | function ConvertA(Value: Double; CurFrom, CurTo: LPCSTR; MaxAge: integer; |
167 | function ConvertA(Value: Double; CurFrom, CurTo: LPCSTR; MaxAge: integer; |
169 | Flags: TVtsCurConvFlags; HistoricDate: TDate): Double; stdcall; |
168 | Flags: TVtsCurConvFlags; HistoricDate: TDate): Double; stdcall; |
170 | var |
169 | var |
171 | x: TVtsCurConv; |
170 | x: TVtsCurConv; |
172 | begin |
171 | begin |
173 | try |
172 | try |
174 | x := TVtsCurConv.Create; |
173 | x := TVtsCurConv.Create; |
175 | try |
174 | try |
176 | x.Secure := Flags and CONVERT_USE_SSL <> 0; |
175 | x.Secure := Flags and CONVERT_USE_SSL <> 0; |
177 | x.MaxAgeSeconds := MaxAge; |
176 | x.MaxAgeSeconds := MaxAge; |
178 | x.ConfirmWebAccess := Flags and CONVERT_CONFIRM_WEB_ACCESS <> 0; |
177 | x.ConfirmWebAccess := Flags and CONVERT_CONFIRM_WEB_ACCESS <> 0; |
179 | x.FallBackToCache := Flags and CONVERT_FALLBACK_TO_CACHE <> 0; |
178 | x.FallBackToCache := Flags and CONVERT_FALLBACK_TO_CACHE <> 0; |
180 | x.InteractiveAPIKeyInput := Flags and CONVERT_NO_INTERACTIVE_API_KEY_INPUT = 0; |
179 | x.InteractiveAPIKeyInput := Flags and CONVERT_NO_INTERACTIVE_API_KEY_INPUT = 0; |
181 | result := x.Convert(value, TVtsCur(CurFrom), TVtsCur(CurTo), HistoricDate); |
180 | result := x.Convert(value, TVtsCur(CurFrom), TVtsCur(CurTo), HistoricDate); |
182 | finally |
181 | finally |
183 | x.Free; |
182 | x.Free; |
184 | end; |
183 | end; |
185 | except |
184 | except |
186 | on E: Exception do |
185 | on E: Exception do |
187 | begin |
186 | begin |
188 | if Flags and CONVERT_DONT_SHOW_ERRORS = 0 then MessageDlg(e.Message, mtError, [mbOk], 0); |
187 | if Flags and CONVERT_DONT_SHOW_ERRORS = 0 then MessageDlg(e.Message, mtError, [mbOk], 0); |
189 | result := -1; |
188 | result := -1; |
190 | end; |
189 | end; |
191 | end; |
190 | end; |
192 | end; |
191 | end; |
193 | 192 | ||
194 | function AcceptedCurrenciesW(WriteTo: LPWSTR; MaxAge: integer; Flags: TVtsCurConvFlags; |
193 | function AcceptedCurrenciesW(WriteTo: LPWSTR; MaxAge: integer; Flags: TVtsCurConvFlags; |
195 | HistoricDate: TDate): Integer; stdcall; |
194 | HistoricDate: TDate): Integer; stdcall; |
196 | var |
195 | var |
197 | x: TVtsCurConv; |
196 | x: TVtsCurConv; |
198 | sl: TStringList; |
197 | sl: TStringList; |
199 | s: WideString; |
198 | s: WideString; |
200 | i: integer; |
199 | i: integer; |
201 | begin |
200 | begin |
202 | try |
201 | try |
203 | x := TVtsCurConv.Create; |
202 | x := TVtsCurConv.Create; |
204 | if Assigned(WriteTo) then sl := TStringList.Create else sl := nil; |
203 | if Assigned(WriteTo) then sl := TStringList.Create else sl := nil; |
205 | try |
204 | try |
206 | x.Secure := Flags and CONVERT_USE_SSL <> 0; |
205 | x.Secure := Flags and CONVERT_USE_SSL <> 0; |
207 | x.MaxAgeSeconds := MaxAge; |
206 | x.MaxAgeSeconds := MaxAge; |
208 | x.ConfirmWebAccess := Flags and CONVERT_CONFIRM_WEB_ACCESS <> 0; |
207 | x.ConfirmWebAccess := Flags and CONVERT_CONFIRM_WEB_ACCESS <> 0; |
209 | x.FallBackToCache := Flags and CONVERT_FALLBACK_TO_CACHE <> 0; |
208 | x.FallBackToCache := Flags and CONVERT_FALLBACK_TO_CACHE <> 0; |
210 | x.InteractiveAPIKeyInput := Flags and CONVERT_NO_INTERACTIVE_API_KEY_INPUT = 0; |
209 | x.InteractiveAPIKeyInput := Flags and CONVERT_NO_INTERACTIVE_API_KEY_INPUT = 0; |
211 | result := x.GetAcceptedCurrencies(sl, HistoricDate); |
210 | result := x.GetAcceptedCurrencies(sl, HistoricDate); |
212 | if Assigned(WriteTo) then |
211 | if Assigned(WriteTo) then |
213 | begin |
212 | begin |
214 | s := ''; |
213 | s := ''; |
215 | for i := 0 to sl.Count - 1 do s := s + WideString(Trim(sl.Strings[i])); |
214 | for i := 0 to sl.Count - 1 do s := s + WideString(Trim(sl.Strings[i])); |
216 | ZeroMemory(WriteTo, (3*result+1)*SizeOf(WideChar)); |
215 | ZeroMemory(WriteTo, (3*result+1)*SizeOf(WideChar)); |
217 | CopyMemory(WriteTo, @s[1], 3*result*SizeOf(WideChar)); |
216 | CopyMemory(WriteTo, @s[1], 3*result*SizeOf(WideChar)); |
218 | end; |
217 | end; |
219 | finally |
218 | finally |
220 | x.Free; |
219 | x.Free; |
221 | if Assigned(WriteTo) then sl.Free; |
220 | if Assigned(WriteTo) then sl.Free; |
222 | end; |
221 | end; |
223 | except |
222 | except |
224 | on E: Exception do |
223 | on E: Exception do |
225 | begin |
224 | begin |
226 | if Flags and CONVERT_DONT_SHOW_ERRORS = 0 then MessageDlg(e.Message, mtError, [mbOk], 0); |
225 | if Flags and CONVERT_DONT_SHOW_ERRORS = 0 then MessageDlg(e.Message, mtError, [mbOk], 0); |
227 | result := -1; |
226 | result := -1; |
228 | end; |
227 | end; |
229 | end; |
228 | end; |
230 | end; |
229 | end; |
231 | 230 | ||
232 | function AcceptedCurrenciesA(WriteTo: LPSTR; MaxAge: integer; Flags: TVtsCurConvFlags; |
231 | function AcceptedCurrenciesA(WriteTo: LPSTR; MaxAge: integer; Flags: TVtsCurConvFlags; |
233 | HistoricDate: TDate): Integer; stdcall; |
232 | HistoricDate: TDate): Integer; stdcall; |
234 | var |
233 | var |
235 | x: TVtsCurConv; |
234 | x: TVtsCurConv; |
236 | sl: TStringList; |
235 | sl: TStringList; |
237 | s: AnsiString; |
236 | s: AnsiString; |
238 | i: integer; |
237 | i: integer; |
239 | begin |
238 | begin |
240 | try |
239 | try |
241 | x := TVtsCurConv.Create; |
240 | x := TVtsCurConv.Create; |
242 | if Assigned(WriteTo) then sl := TStringList.Create else sl := nil; |
241 | if Assigned(WriteTo) then sl := TStringList.Create else sl := nil; |
243 | try |
242 | try |
244 | x.Secure := Flags and CONVERT_USE_SSL <> 0; |
243 | x.Secure := Flags and CONVERT_USE_SSL <> 0; |
245 | x.MaxAgeSeconds := MaxAge; |
244 | x.MaxAgeSeconds := MaxAge; |
246 | x.ConfirmWebAccess := Flags and CONVERT_CONFIRM_WEB_ACCESS <> 0; |
245 | x.ConfirmWebAccess := Flags and CONVERT_CONFIRM_WEB_ACCESS <> 0; |
247 | x.FallBackToCache := Flags and CONVERT_FALLBACK_TO_CACHE <> 0; |
246 | x.FallBackToCache := Flags and CONVERT_FALLBACK_TO_CACHE <> 0; |
248 | x.InteractiveAPIKeyInput := Flags and CONVERT_NO_INTERACTIVE_API_KEY_INPUT = 0; |
247 | x.InteractiveAPIKeyInput := Flags and CONVERT_NO_INTERACTIVE_API_KEY_INPUT = 0; |
249 | result := x.GetAcceptedCurrencies(sl, HistoricDate); |
248 | result := x.GetAcceptedCurrencies(sl, HistoricDate); |
250 | if Assigned(WriteTo) then |
249 | if Assigned(WriteTo) then |
251 | begin |
250 | begin |
252 | s := ''; |
251 | s := ''; |
253 | for i := 0 to sl.Count - 1 do s := s + AnsiString(Trim(sl.Strings[i])); |
252 | for i := 0 to sl.Count - 1 do s := s + AnsiString(Trim(sl.Strings[i])); |
254 | ZeroMemory(WriteTo, (3*result+1)*SizeOf(AnsiChar)); |
253 | ZeroMemory(WriteTo, (3*result+1)*SizeOf(AnsiChar)); |
255 | CopyMemory(WriteTo, @s[1], 3*result*SizeOf(AnsiChar)); |
254 | CopyMemory(WriteTo, @s[1], 3*result*SizeOf(AnsiChar)); |
256 | end; |
255 | end; |
257 | finally |
256 | finally |
258 | x.Free; |
257 | x.Free; |
259 | if Assigned(WriteTo) then sl.Free; |
258 | if Assigned(WriteTo) then sl.Free; |
260 | end; |
259 | end; |
261 | except |
260 | except |
262 | on E: Exception do |
261 | on E: Exception do |
263 | begin |
262 | begin |
264 | if Flags and CONVERT_DONT_SHOW_ERRORS = 0 then MessageDlg(e.Message, mtError, [mbOk], 0); |
263 | if Flags and CONVERT_DONT_SHOW_ERRORS = 0 then MessageDlg(e.Message, mtError, [mbOk], 0); |
265 | result := -1; |
264 | result := -1; |
266 | end; |
265 | end; |
267 | end; |
266 | end; |
268 | end; |
267 | end; |
269 | 268 | ||
270 | function DownloadNow(Flags: TVtsCurConvFlags; HistoricDate: TDate): HRESULT; stdcall; |
269 | function DownloadNow(Flags: TVtsCurConvFlags; HistoricDate: TDate): HRESULT; stdcall; |
271 | var |
270 | var |
272 | x: TVtsCurConv; |
271 | x: TVtsCurConv; |
273 | begin |
272 | begin |
274 | try |
273 | try |
275 | x := TVtsCurConv.Create; |
274 | x := TVtsCurConv.Create; |
276 | try |
275 | try |
277 | x.Secure := Flags and CONVERT_USE_SSL <> 0; |
276 | x.Secure := Flags and CONVERT_USE_SSL <> 0; |
278 | x.MaxAgeSeconds := 0; // Always Download |
277 | x.MaxAgeSeconds := 0; // Always Download |
279 | x.ConfirmWebAccess := Flags and CONVERT_CONFIRM_WEB_ACCESS <> 0; |
278 | x.ConfirmWebAccess := Flags and CONVERT_CONFIRM_WEB_ACCESS <> 0; |
280 | x.FallBackToCache := Flags and CONVERT_FALLBACK_TO_CACHE <> 0; |
279 | x.FallBackToCache := Flags and CONVERT_FALLBACK_TO_CACHE <> 0; |
281 | x.InteractiveAPIKeyInput := Flags and CONVERT_NO_INTERACTIVE_API_KEY_INPUT = 0; |
280 | x.InteractiveAPIKeyInput := Flags and CONVERT_NO_INTERACTIVE_API_KEY_INPUT = 0; |
282 | x.Convert(1, 'USD', 'USD', HistoricDate); |
281 | x.Convert(1, 'USD', 'USD', HistoricDate); |
283 | result := S_VTSCONV_OK |
282 | result := S_VTSCONV_OK |
284 | finally |
283 | finally |
285 | x.Free; |
284 | x.Free; |
286 | end; |
285 | end; |
287 | except |
286 | except |
288 | on E: Exception do |
287 | on E: Exception do |
289 | begin |
288 | begin |
290 | if Flags and CONVERT_DONT_SHOW_ERRORS = 0 then MessageDlg(e.Message, mtError, [mbOk], 0); |
289 | if Flags and CONVERT_DONT_SHOW_ERRORS = 0 then MessageDlg(e.Message, mtError, [mbOk], 0); |
291 | result := E_VTSCONV_GENERIC_FAILURE; |
290 | result := E_VTSCONV_GENERIC_FAILURE; |
292 | end; |
291 | end; |
293 | end; |
292 | end; |
294 | end; |
293 | end; |
295 | 294 | ||
296 | exports |
295 | exports |
297 | DeleteAPIKey, |
296 | DeleteAPIKey, |
298 | WriteAPIKeyW, |
297 | WriteAPIKeyW, |
299 | WriteAPIKeyA, |
298 | WriteAPIKeyA, |
300 | ReadAPIKeyW, |
299 | ReadAPIKeyW, |
301 | ReadAPIKeyA, |
300 | ReadAPIKeyA, |
302 | ConvertW, |
301 | ConvertW, |
303 | ConvertA, |
302 | ConvertA, |
304 | AcceptedCurrenciesW, |
303 | AcceptedCurrenciesW, |
305 | AcceptedCurrenciesA, |
304 | AcceptedCurrenciesA, |
306 | DownloadNow; |
305 | DownloadNow; |
307 | 306 | ||
308 | begin |
307 | begin |
309 | end. |
308 | end. |
310 | 309 |