📄 globals.pas
字号:
unit Globals;
{$IFDEF VER150}
{$WARN UNSAFE_CODE OFF}
{$ENDIF}
interface
uses
{$IFDEF VER140}
Variants,
{$ENDIF}
{$IFDEF VER150}
Variants,
{$ENDIF}
Windows,Messages,SysUtils,Classes,Graphics,StdCtrls,Forms,Dialogs,Controls,
ShellAPI,ActiveX,OPCDA;
type
itemIDStrings = record
trunk,branch,leaf:string[255];
end;
type
itemProps = record
PropID: longword;
tagname: string[64];
dataType:integer;
end;
const
IID_IUnknown: TIID = '{00000000-0000-0000-C000-000000000046}';
posItems: array[0..22] of itemProps =
((PropID: 5000; tagname: 'Complete'; dataType:VT_BSTR),
(PropID: 5001; tagname: 'Date.Complete'; dataType:VT_BSTR),
(PropID: 5002; tagname: 'Date.Parts.Day'; dataType:VT_UI2),
(PropID: 5003; tagname: 'Date.Parts.Month'; dataType:VT_UI2),
(PropID: 5004; tagname: 'Date.Parts.Year'; dataType:VT_UI2),
(PropID: 5005; tagname: 'Time.Complete'; dataType:VT_BSTR),
(PropID: 5006; tagname: 'Time.Parts.Hour'; dataType:VT_UI2),
(PropID: 5007; tagname: 'Time.Parts.Min'; dataType:VT_UI2),
(PropID: 5008; tagname: 'Time.Parts.Seconds'; dataType:VT_UI2),
(PropID: 5009; tagname: 'Time.Parts.Millseconds'; dataType:VT_UI2),
(PropID: 5010; tagname: 'Inverted.Date.Complete'; dataType:VT_BSTR),
(PropID: 5011; tagname: 'Inverted.Date.Day'; dataType:VT_UI2),
(PropID: 5012; tagname: 'Inverted.Date.Month'; dataType:VT_UI2),
(PropID: 5013; tagname: 'Inverted.Date.Year'; dataType:VT_UI2),
(PropID: 5014; tagname: 'Inverted.Time.Complete'; dataType:VT_BSTR),
(PropID: 5015; tagname: 'Inverted.Time.Hour'; dataType:VT_UI2),
(PropID: 5016; tagname: 'Inverted.Time.Min'; dataType:VT_UI2),
(PropID: 5017; tagname: 'Inverted.Time.Seconds'; dataType:VT_UI2),
(PropID: 5018; tagname: 'Inverted.Time.Millseconds'; dataType:VT_UI2),
(PropID: 5019; tagname: 'Test_Tag_1.Actual'; dataType:VT_UI2),
(PropID: 5020; tagname: 'Test_Tag_1.Inverted'; dataType:VT_UI2),
(PropID: 5021; tagname: 'Test_Tag_2.Actual'; dataType:VT_UI2),
(PropID: 5022; tagname: 'Test_Tag_2.Inverted'; dataType:VT_UI2));
io2Read = 1;
io2Write = 2;
io2Refresh = 3;
io2Change = 4;
var
itemValues:array[0..23] of word;
function ScanToChar(const theString:string; var start:integer;theChar:char):string;
function ReturnPropIDFromTagname(const s1:string):longword;
function ReturnTagnameFromPropID(PropID:longword):string;
function CanPropIDBeWritten(i:longword):boolean;
function ReturnDataTypeFromPropID(i:longword):integer;
procedure DataTimeToOPCTime(cTime:TDateTime; var OPCTime:TFileTime);
function ConvertVariant(cv:variant; reqDataType:TVarType):variant;
implementation
function ScanToChar(const theString:string; var start:integer;theChar:char):string;
var
tempS:string;
finish:boolean;
nextloc,strLength: integer;
begin
{$R-}
strLength := length(theString);
finish := false;
SetLength(tempS,strLength);
result := tempS;
nextloc := 1;
while not finish do
begin
if (start < 256) and (theString[start] <> theChar) and
(theString[start] <> chr(13)) and (start <= strLength) then
begin
tempS[nextloc] := theString[start];
nextloc := succ(nextloc);
start := succ(start);
end
else
begin
SetLength(tempS,nextloc-1); {this sets the length of the string}
finish:=true; {exit the loop}
result:=tempS; {return the value}
end;
end;
{$R+}
end;
function ReturnPropIDFromTagname(const s1:string):longword;
var
i:integer;
begin
result:=0;
for i:= low(posItems) to high(posItems) do
if posItems[i].tagname = s1 then
begin
result:=posItems[i].PropID;
Exit;
end;
end;
function ReturnTagnameFromPropID(PropID:longword):string;
var
i:integer;
begin
result:='';
for i:= low(posItems) to high(posItems) do
if posItems[i].PropID = PropID then
begin
result:=posItems[i].tagname;
Exit;
end;
end;
function CanPropIDBeWritten(i:longword):boolean;
begin
i:= i - posItems[low(posItems)].PropID;
result:=boolean(i in [19..22]); //the test Test_Tag_X's
end;
function ReturnDataTypeFromPropID(i:longword):integer;
var
x:longword;
begin
x:= i - posItems[low(posItems)].PropID;
if (x <= high(posItems)) then
result:=posItems[x].dataType
else
result:=VT_UI2;
end;
procedure DataTimeToOPCTime(cTime:TDateTime; var OPCTime:TFileTime);
var
sTime:TSystemTime;
begin
DateTimeToSystemTime(cTime,sTime);
SystemTimeToFileTime(sTime,OPCTime);
LocalFileTimeToFileTime(OPCTime,OPCTime);
end;
function ConvertVariant(cv:variant; reqDataType:TVarType):variant;
begin
try
result:=VarAsType(cv,reqDataType)
except
on EVariantError do result:=DISP_E_TYPEMISMATCH;
end;
end;
end.
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -