-
Notifications
You must be signed in to change notification settings - Fork 58
/
FIBPlatforms.pas
175 lines (147 loc) · 4.1 KB
/
FIBPlatforms.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
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
{***************************************************************}
{ FIBPlus - component library for direct access to Firebird and }
{ InterBase databases }
{ }
{ FIBPlus is based in part on the product }
{ Free IB Components, written by Gregory H. Deatz for }
{ Hoagland, Longo, Moran, Dunst & Doukas Company. }
{ mailto:[email protected] }
{ }
{ Copyright (c) 1998-2013 Devrace Ltd. }
{ Written by Serge Buzadzhy ([email protected]) }
{ }
{ ------------------------------------------------------------- }
{ FIBPlus home page: http://www.fibplus.com/ }
{ FIBPlus support : http://www.devrace.com/support/ }
{ ------------------------------------------------------------- }
{ }
{ Please see the file License.txt for full license information }
{***************************************************************}
unit FIBPlatforms;
interface
{$I FIBPlus.inc}
uses
{$IFDEF D_XE2}
System.UITypes,System.Types,
{$ENDIF}
{$IFDEF WINDOWS}
Windows,Messages,SysUtils;
{$ENDIF}
{$IFDEF MACOS}
Classes,SysUtils,Macapi.CoreServices,Macapi.Mach,Macapi.Foundation,Macapi.AppKit,Macapi.CocoaTypes;
{$ENDIF MACOS}
{$IFDEF WINDOWS}
const
CLRF =#13#10;
{$ELSE}
const
CLRF =#10;
{$ENDIF}
type
{$IFDEF D2009+}
FIBByteString=RawByteString;
TDataBuffer=PByte;
{$ELSE}
FIBByteString=Ansistring;
TDataBuffer=PChar ;
{$ENDIF}
PFIBByteString=^FIBByteString;
DWORD = LongWord;
{$EXTERNALSYM DWORD}
LONG64 = Int64;
{$IFNDEF D6+}
PInteger=^Integer;
PWORD = ^Word;
PDouble =^Double;
PByte =^Byte;
PSmallInt=^SmallInt;
PShortInt=^ShortInt;
PSingle=^Single;
HRESULT = type Longint;
{$ENDIF}
function FIBGetTickCount: Cardinal;
procedure TerminateApplication;
function ApplicationPath:string;
function CurrentThreadID:DWORD;
{$IFNDEF D7+}
function WideCompareStr(const S1, S2: WideString): Integer;
{$ENDIF}
const
{$IFDEF D2009+}
ZeroData=0;
{$ELSE}
ZeroData=#0;
{$ENDIF}
implementation
{$IFNDEF D7+}
function DumbItDownFor95(const S1, S2: WideString; CmpFlags: Integer): Integer;
var
a1, a2: AnsiString;
begin
a1 := s1;
a2 := s2;
Result := CompareStringA(LOCALE_USER_DEFAULT, CmpFlags, PChar(a1), Length(a1),
PChar(a2), Length(a2)) - 2;
end;
function WideCompareStr(const S1, S2: WideString): Integer;
begin
SetLastError(0);
Result := CompareStringW(LOCALE_USER_DEFAULT, 0, PWideChar(S1), Length(S1),
PWideChar(S2), Length(S2)) - 2;
case GetLastError of
0: ;
ERROR_CALL_NOT_IMPLEMENTED: Result := DumbItDownFor95(S1, S2, 0);
else
RaiseLastWin32Error;
end;
end;
{$ENDIF}
{$IFDEF WINDOWS}
function FIBGetTickCount: Cardinal;
begin
Result := Windows.GetTickCount;
end;
procedure TerminateApplication;
begin
PostQuitMessage(0);
end;
function ApplicationPath:string;
begin
Result:=ExtractFilePath(ParamStr(0))
end;
function CurrentThreadID:DWORD;
begin
Result:=GetCurrentThreadID
end;
{$ENDIF}
{$IFDEF MACOS}
function FIBGetTickCount: Cardinal;
begin
Result := AbsoluteToNanoseconds(mach_absolute_time) div 1000000;
end;
procedure TerminateApplication;
var
NSApp: NSApplication;
begin
NSApp:=TNSApplication.Wrap(TNSApplication.OCClass.sharedApplication);
if Assigned(NSApp) then
NSApp.terminate(nil);
NSApp:=nil
end;
function ApplicationPath:string;
var
MainBundle: NSBundle;
begin
MainBundle:=TNSBundle.Wrap(TNSBundle.OCClass.mainBundle);
if Assigned(MainBundle) then
Result:=ExtractFilePath(MainBundle.bundlePath.UTF8String)
else
Result:='';
MainBundle:=nil;
end;
function CurrentThreadID:DWORD;
begin
Result:=TThread.CurrentThread.ThreadID
end;
{$ENDIF}
end.