-
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathunitUtility.pas
More file actions
48 lines (43 loc) · 1.07 KB
/
Copy pathunitUtility.pas
File metadata and controls
48 lines (43 loc) · 1.07 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
unit unitUtility;
interface
uses
System.SysUtils, System.Variants, System.Classes, FireDAC.Comp.Client;
function CnvVarToInt(v: variant): integer;
function GetHRTypeStr(AHRTypeID: integer; AConnection: TFDConnection): string;
implementation
function CnvVarToInt(v: variant): integer;
var
i, Code: integer;
begin
i := 0;
// Exception class EVariantTypeCastError with message
// 'Could not convert variant of type (Null) into type (Integer)'.
if VarIsNull(v) then
i := 0
else
begin
if VarIsStr(v) then
begin
System.Val(v, Code, i);
if Code <> 0 then // on error
i := 0;
end
else
i := v; // Should work!
end;
result := i;
end;
function GetHRTypeStr(AHRTypeID: integer; AConnection: TFDConnection): string;
var
SQL: string;
begin
result := '';
if Assigned(AConnection) and AConnection.Connected then
begin
// Get string for captions
SQL := 'SELECT Caption FROM [SCM_Coach].[dbo].[HRType] WHERE HRTypeID = :id';
// returns variant
result := AConnection.ExecSQLScalar(SQL, [AHRTypeID]);
end;
end;
end.