bocomdlp.dpr

来自「把类封装成dll文件」· DPR 代码 · 共 178 行

DPR
178
字号
library bocomdlp;

{ Important note about DLL memory management: ShareMem must be the
  first unit in your library's USES clause AND your project's (select
  Project-View Source) USES clause if your DLL exports any procedures or
  functions that pass strings as parameters or function results. This
  applies to all strings passed to and from your DLL--even those that
  are nested in records and classes. ShareMem is the interface unit to
  the BORLNDMM.DLL shared memory manager, which must be deployed along
  with your DLL. To avoid using BORLNDMM.DLL, pass string information
  using PChar or ShortString parameters. }

uses
  SysUtils,
  Classes,
  Bocom in 'Bocom.pas';

{$R *.res}
type
  PBocom=^TBocom;

var
  //we need maintain a list of device objects
  devlist:TList;

//new a bocom object and connect to the server
//return a handle to the connection,-1 if failed
function OpenDevice(svrip,svrport:PChar):Integer;stdcall;
var
  dev:TBocom;
  h:Integer;
begin
  dev:=TBocom.create;
  //connect
  dev.Connection(svrip,svrport);
  //add to device list
  h:=devlist.Add(@dev);
  result:=h;
end;

//disconnect from the server and release.
function CloseDevice(h:Integer):Integer;stdcall;
var
  pdev:PBocom;
begin
  result:=-1;
  pdev:=devlist[h];
  if pdev=nil then exit;
  pdev^.DisConnection;
  pdev^.Free;
  devlist[h]:=nil;
  result:=0;
end;

//login
function Login(h:Integer;user,password:PChar):Integer;stdcall;
var
  pdev:PBocom;
begin
  result:=-1;
  pdev:=devlist[h];
  if pdev=nil then exit;
  pdev^.Login(user,password);
  pdev^.SendMessage;
  result:=0;
end;

//logout
function Logout(h:Integer):Integer;stdcall;
var
  pdev:PBocom;
begin
  result:=-1;
  pdev:=devlist[h];
  if pdev=nil then exit;
  pdev^.Unlogin;
  pdev^.SendMessage;
  result:=0;
end;

//open a video win
function OpenVideoWin(h:Integer;winname:PChar;left,top,width,height,videoid:Integer):Integer;stdcall;
var
  pdev:PBocom;
begin
  result:=-1;
  pdev:=devlist[h];
  if pdev=nil then exit;
  pdev^.VideoShow(winname,IntToStr(left),IntToStr(top),IntToStr(width),IntToStr(height),IntToStr(videoid));
  pdev^.SendMessage;
  result:=0;
end;

//close a video win
function CloseVideoWin(h:Integer;winname:PChar):Integer;stdcall;
var
  pdev:PBocom;
begin
  result:=-1;
  pdev:=devlist[h];
  if pdev=nil then exit;
  pdev^.VideoClose(winname,'');
  pdev^.SendMessage;
  result:=0;
end;

//open a rgb win
function OpenRgbWin(h:Integer;winname:PChar;left,top,width,height,rgbid:Integer):Integer;stdcall;
var
  pdev:PBocom;
begin
  result:=-1;
  pdev:=devlist[h];
  if pdev=nil then exit;
  pdev^.RGBShow(winname,IntToStr(left),IntToStr(top),IntToStr(width),IntToStr(height),IntToStr(rgbid));
  pdev^.SendMessage;
  result:=0;
end;

//close a rgb win
function CloseRgbWin(h:Integer;winname:PChar):Integer;stdcall;
var
  pdev:PBocom;
begin
  result:=-1;
  pdev:=devlist[h];
  if pdev=nil then exit;
  pdev^.RGBClose(winname);
  pdev^.SendMessage;
  result:=0;
end;

//open netpc win
function OpenNetPcWin(h:Integer;winname:PChar;left,top,width,height:Integer;netip:PChar):Integer;stdcall;
var
  pdev:PBocom;
begin
  result:=-1;
  pdev:=devlist[h];
  if pdev=nil then exit;
  pdev^.NetPcShow(winname,IntToStr(left),IntToStr(top),IntToStr(width),netip);
  pdev^.SendMessage;
  result:=0;
end;

//close netpc win
function CloseNetPcWin(h:Integer;winname:PChar):Integer;stdcall;
var
  pdev:PBocom;
begin
  result:=-1;
  pdev:=devlist[h];
  if pdev=nil then exit;
  pdev^.VideoClose(winname,'');
  pdev^.SendMessage;
  result:=0;
end;

exports
  OpenDevice,
  CloseDevice,
  Login,
  Logout,
  OpenVideoWin,
  CloseVideoWin,
  OpenRgbWin,
  CloseRgbWin,
  OpenNetPcWin,
  CloseNetPcWin;

begin

  //initialize the device list
  devlist:=TList.Create;


end.

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?