dll完成的功能就是把接收到的数据存到sqlserver数据中,请富翁们给看看library MySave;{ 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 ShareMem, Windows, System, SysUtils, Variants, Classes, Adodb, math;{$R *.res}//定义接收采集端数据结构type TReceiveData = record NodeID: integer; COleDateTime: TDateTime; AngleX1: WORD; AngleY1: WORD; AngleX2: WORD; AngleY2: WORD; AngleX3: WORD; AngleY3: WORD; AngleX4: WORD; AngleY4: WORD; PullForce1: WORD; PullForce2: WORD; PullForce3: WORD; WindSpeed: WORD; WindOrient: WORD; Voltage: WORD; Temperature1: WORD; Temperature2: WORD; Temperature3: WORD; Temperature4: WORD; SensorTemp: WORD; Reserved0: WORD; Reserved1: WORD; Reserved2: WORD; Reserved3: WORD; Reserved4: WORD; Reserved5: WORD; Reserved6: WORD; Reserved7: WORD; Reserved8: WORD; end; TagData = ^TReceiveData; TMyArry = array of shortstring; TSQLArray = array[0..27] of double; TSQLSaveData = ^TSQLArray;var ADOConn: Tadoconnection; ADOQry: TADOQuery; ADOQryTable: TADOQuery;//角度参数换算function GetValueJiaoD(JD: integer): Double;var PI: Double;begin PI := 3.14; Result := JD; Result := (Result - 1024) / 1638; Result := ArcSin(Result) * 180 / PI;end;//拉力参数换算function GetValueLaL(LL: integer): Double;begin Result := LL;end;//风向参数换算function GetValueFengX(FX: integer): Double;begin Result := FX;end;//风速参数换算function GetValueFengS(FS: integer): Double;begin Result := FS; Result := Result / 7.5;end;//温度参数换算function GetValueWenD(WD: integer): Double;begin Result := WD; Result := (Result - 197) / (-1.083);end;//链接数据库 服务器名称:ServerID 用户名:UserName 用户密码:UserPWDfunction ConnectServer(ServerID, UserName, UserPWD: PChar): Boolean; stdcall;begin ADOConn := Tadoconnection.Create(nil); try ADOConn.ConnectionString := 'Provider=SQLOLEDB.1;Persist Security Info=True;Data Source=' + ServerID; ADOConn.Open(UserName, UserPWD); Result := True; except Result := False; end;end;//获取需要存储的表名称function GetTableName: TMyArry;var TableName: TMYArry; i: integer;begin ADOQryTable := TADOQuery.Create(nil); ADOQryTable.Connection := ADOConn; try with ADOQryTable do begin Close; SQL.Text := 'select TableName from TableINFO order by OrderID ASC'; Open; end; Setlength(TableName, ADOQryTable.RecordCount); ADOQryTable.First; for i := 0 to (ADOQryTable.RecordCount - 1) do begin TableName := ADOQryTable.FieldByName('TableName').AsString; ADOQryTable.Next; end; Result := TableName; except Exit; end;end;//保存数据到数据库:结构体指针procedure SaveData(a: TagData); stdcall;var SystemTime: TSystemTime; SaveDateTime: shortstring; ReceiveData: array of double; ReceiveTable: TMyArry; k: integer;begin GetLocalTime(SystemTime); SaveDateTime := IntToStr(SystemTime.wYear) + '-' + IntToStr(SystemTime.wMonth) + '-' + IntToStr(SystemTime.wDay) + ' ' + IntToStr(SystemTime.wHour) + ':' + IntToStr(SystemTime.wMinute) + ':' + IntToStr(SystemTime.wSecond); //获得需要存储数据 ReceiveTable := GetTableName; Setlength(ReceiveData, ADOQryTable.RecordCount); ReceiveData[0] := GetValueJiaoD(a.AngleX1); ReceiveData[1] := GetValueJiaoD(a.AngleY1); ReceiveData[2] := GetValueJiaoD(a.AngleX2); ReceiveData[3] := GetValueJiaoD(a.AngleY2); ReceiveData[4] := GetValueJiaoD(a.AngleX3); ReceiveData[5] := GetValueJiaoD(a.AngleY3); ReceiveData[6] := GetValueJiaoD(a.AngleX4); ReceiveData[7] := GetValueJiaoD(a.AngleY4); ReceiveData[8] := GetValueLaL(a.PullForce1); ReceiveData[9] := GetValueLaL(a.PullForce2); ReceiveData[10] := GetValueLaL(a.PullForce3); ReceiveData[11] := GetValueFengS(a.WindSpeed); ReceiveData[12] := GetValueFengX(a.WindOrient); ReceiveData[13] := a.Voltage; ReceiveData[14] := GetValueWenD(a.Temperature1); ReceiveData[15] := GetValueWenD(a.Temperature2); ReceiveData[16] := GetValueWenD(a.Temperature3); ReceiveData[17] := GetValueWenD(a.Temperature4); ReceiveData[18] := a.SensorTemp; //开始存储数据 ADOQry := TADOQuery.Create(nil); ADOQry.Connection := ADOConn; for k := 0 to (ADOQryTable.RecordCount - 1) do try with ADOQry do begin Close; SQL.Text := 'insert into ' + Trim(ReceiveTable[k]) + ' values(' + IntToStr(a.NodeID) + ',' + FloatToStr(ReceiveData[k]) + ',' + QuotedStr(SaveDateTime) + ')'; ExecSQL; end; except Exit; end;end;//保存数据到数据库:指针数组procedure SQLSaveData(NodeID: integer; l_temp: double; Pval: TSQLSaveData; count: integer); stdcall;var SystemTime: TSystemTime; SaveDateTime: shortstring; ReceiveTable: TMyArry; m: integer;begin GetLocalTime(SystemTime); SaveDateTime := IntToStr(SystemTime.wYear) + '-' + IntToStr(SystemTime.wMonth) + '-' + IntToStr(SystemTime.wDay) + ' ' + IntToStr(SystemTime.wHour) + ':' + IntToStr(SystemTime.wMinute) + ':' + IntToStr(SystemTime.wSecond); //获得需要存储表名称 ReceiveTable := GetTableName; //开始存储数据 ADOQry := TADOQuery.Create(nil); ADOQry.Connection := ADOConn; for m := 0 to (ADOQryTable.RecordCount - 1) do try with ADOQry do begin Close; SQL.Text := 'insert into ' + Trim(ReceiveTable[m]) + ' values(' + IntToStr(NodeID) + ',' + FloatToStr(Pval[m]) + ',' + QuotedStr(SaveDateTime) + ')'; ExecSQL; end; except Exit; end;end;//导出函数exports ConnectServer name 'ConnectSever', SaveData name 'SaveData', SQLSaveData name 'SQLSaveData';beginend.