ipworks问题,500分,另外开贴给!
109 The component must be Active for this operation.
下面是线程代码:
unit SnmpDataSampUnit;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, ipwcore, ipwsnmpmgr, ExtCtrls, DB, ADODB, comObj, ActiveX;
type
SnmpDataSamp = class(TThread)
private
{ Private declarations }
Fsnmp:tipwsnmpmgr;
Ftimer:ttimer;
Fsamptime:integer;
Fipaddress:string;
Fsnmpver:integer;//v1=1;v2c=2;v3=3;
FAdoConn:TADOConnection;
FADOQuery:TADOQuery;
procedure ontimer(sender:tobject);
procedure sampledata;
protected
procedure Execute; override;
destructor Destroy; override;
public
constructor create(ipaddress:string;fsamptime:integer;snmpver:integer;user:string;pw:string);
end;
implementation
{ Important: Methods and properties of objects in visual components can only be
used in a method called using Synchronize, for example,
Synchronize(UpdateCaption);
and UpdateCaption could look like,
procedure SnmpDataSamp.UpdateCaption;
begin
Form1.Caption := 'Updated in a thread';
end; }
{ SnmpDataSamp }
constructor SnmpDataSamp.create(ipaddress:string;fsamptime:integer;snmpver:integer;user:string;pw:string);
begin
//-----------------------------------------------------------------------------//
FreeOnTerminate:=false;
Fsnmp:=tipwsnmpmgr.Create(nil);
Ftimer:=ttimer.Create(nil);
Ftimer.Interval:=fsamptime*1000;
ftimer.Enabled:=false;
fsnmp.RemoteHost:=ipaddress;
fsnmp.Community:='public';
if snmpver=1 then
begin
fsnmp.SNMPVersion:=TipwsnmpmgrSNMPVersions(1);
fsnmp.User:='';
fsnmp.Password:='';
end
else if snmpver=2 then
begin
fsnmp.SNMPVersion:=TipwsnmpmgrSNMPVersions(2);
fsnmp.User:='';
fsnmp.Password:='';
end
else begin
fsnmp.SNMPVersion:=TipwsnmpmgrSNMPVersions(3);
fsnmp.User:=user;
fsnmp.Password:=pw;
end;
//-----------------------------------------------------------------------------//
CoInitialize(nil);
FAdoConn:=TAdoconnection.Create(nil);
FAdoConn.LoginPrompt:=false;
FAdoConn.ConnectionString:='Provider=SQLOLEDB.1;Password=nmss;Persist Security Info=True;User ID=nmss;Initial Catalog=NMSD;Data Source=WTY';
FAdoQuery:=TAdoQuery.Create(nil);
FAdoQuery.Connection:=FAdoConn;
try
FAdoConn.Connected:=true;
except
showmessage('不能连接数据库!');
exit;
end;
//-----------------------------------------------------------------------------//
inherited create(false);
end;
//-----------------------------------------------------------------------------//
destructor SnmpDataSamp.Destroy;
begin
inherited destroy;
Fsnmp.Active:=false;
fsnmp.Free;
ftimer.Enabled:=false;
ftimer.Free;
CoUninitialize;
FAdoquery.Free;
FAdoconn.Connected:=false;
FAdoconn.Free;
end;
//-----------------------------------------------------------------------------//
procedure SnmpDataSamp.sampledata;
var
i:integer;
j,portcount,k:integer;
valuestr:tstrings;
timestr:string;
sqlstr:string;
begin
fsnmp.Active:=false;
try
timestr:=datetimetostr(now);
valuestr:=tstringlist.Create;
valuestr.Clear;
fsnmp.ObjCount:=1;
fsnmp.ObjId[1]:='1.3.6.1.2.1.2.1.0';
fsnmp.Active:=true;//
fsnmp.SendGetRequest;
portcount:=strtoint(fsnmp.ObjValue[1]);
fsnmp.Active:=false;//
i:=strtoint(fsnmp.ObjValue[1])*22;
fsnmp.ObjId[1]:='1.3.6.1.2.1.2.2';
while i>0 do
begin
fsnmp.Active:=true;///
fsnmp.SendGetNextRequest;
valuestr.Add(fsnmp.ObjValue[1]);
dec(i);
fsnmp.Active:=false;///
end;
for j:=0 to portcount-1 do
begin
////////////////////////////////////
sqlstr:='insert into datatable (ipaddress,dtstr,port,mtu,speed,portadstate,portoperstate,lastchange,inoctets,inucastpkts,innucastpkts,indiscards,inerrors,inunknownprotos,outoctets,outucastpkts,outnucastpkts,outdiscards,outerrors,outqlen)';
sqlstr:=sqlstr+' values('''+Fsnmp.RemoteHost+''',';
sqlstr:=sqlstr+''''+timestr+''',';
for k:=0 to 21 do
begin
if ((k=1) or (k=2) or (k=5) or (k=21)) then
continue
else begin
/////////////////////////////
if K<>20 then
sqlstr:=sqlstr+''''+valuestr.Strings[k*portcount+j]+''','
else sqlstr:=sqlstr+''''+valuestr.Strings[k*portcount+j]+''')';
end;
end;
///////////////////////////////
with Fadoquery do
begin
close;
sql.Clear;
sql.Text:=sqlstr;
Execsql;
end;
end;
finally
valuestr.Free;
end;
end;
//-----------------------------------------------------------------------------//
procedure SnmpDataSamp.ontimer(Sender:Tobject);
begin
Synchronize(sampledata);
end;
//-----------------------------------------------------------------------------//
procedure SnmpDataSamp.Execute;
begin
{ Place thread code here }
ftimer.OnTimer:=ontimer;
ftimer.Enabled:=true;
end;
end.
测试代码:
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, DB, ADODB, SnmpDataSampUnit, StdCtrls, ipwcore, ipwsnmpmgr;
type
TForm1 = class(TForm)
Button1: TButton;
Button2: TButton;
ipwSNMPMgr1: TipwSNMPMgr;
procedure Button1Click(Sender: TObject);
procedure Button2Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
snmp1,snmp2:snmpdatasamp;
implementation
{$R *.dfm}
procedure TForm1.Button1Click(Sender: TObject);
begin
///
snmp1:=SnmpDataSamp.create('202.202.41.173',30,1,'','');
end;
procedure TForm1.Button2Click(Sender: TObject);
begin
////
snmp2:=SnmpDataSamp.create('202.202.41.175',30,1,'','');
end;
end.
相关推荐
n.Software.IPWorks!.2016.V16.0.6446
The most comprehensive suite of components for professional Internet development. Trusted by almost every Fortune 500 and Global 2000, as well as thousands of independent developers worldwide. IP*Works! is a comprehensive framework for Internet development and is the core building block for most /n software products. IP*Works! eliminates the complexity of Internet development, providing programmable, SSL-enabled components that facilitate tasks such as ensuring security, sending email, transferring files, managing networks, browsing the Web, consuming Web Services, etc.
Delphi 13.1 中使用 IPWorks BLE 2024 开发蓝牙应用的完整指南
蓝牙低功耗(BLE)技术凭借低功耗与灵活连接,已成为物联网和移动互联场景的核心通信方式。在 Delphi 环境下进行 BLE 开发,开发者常被 WinRT 异步模型和跨平台桥接问题困扰。nSoftware IPWorks BLE 2024 通过封装 VCL 组件,将中央设备、外围设备、Beacon 三种角色统一为可视化控件,极大降低了 GATT 协议栈的工程门槛。理解 BLE 的角色不对称性、GATT 服务表结构以及扫描、连接、服务发现、特征值读写的异步链路,是快速落地的关键。本文聚焦 Delphi 13.
Delphi 12.3 原生 HTTPS/FTP/SNMP 组件 IPWorks 集成指南
HTTPS 和 FTP 是现代客户端通信的基础协议,其底层依赖 SSL/TLS 加密、Socket 连接管理与协议状态机。nSoftware IPWorks 提供 Delphi 原生实现的 THTTP、TFTP、TSNMP 等组件,绕过 Indy 的复杂封装与 OpenSSL 动态库依赖,直接集成 TLS 1.2/1.3 协商、HTTP/2 Server Push、multipart 文件上传及断点续传能力。技术价值在于设计时可视化配置、跨平台 FMX 支持(Windows/macOS/iOS/Androi
Delphi 13.1下IPWorks BLE控件实战:扫描连接与GATT读写指南
在Windows桌面应用开发中,实现低功耗蓝牙(BLE)通信一直是Delphi开发者的痛点。原生VCL与FMX框架缺乏对BLE协议栈的良好封装,直接调用WinRT API或使用不成熟的第三方组件,往往陷入复杂的异步回调处理。IPWorks BLE 2024 Delphi Edition以可视化组件形式,将BLE中央设备与外围设备的核心功能封装为事件驱动接口。它完整覆盖设备扫描、连接管理、GATT服务发现、特征读写与通知订阅等关键链路,让开发者无需深入底层协议即可构建稳定的蓝牙上位机应用。本文基于Delphi
弱电网下光伏并网逆变器序阻抗建模仿真复现扫频法【序阻抗判断稳定性】
内容概要:本文聚焦于弱电网条件下光伏并网逆变器的序阻抗建模与稳定性分析,系统阐述了基于扫频法的阻抗特性仿真与复现方法。通过构建正负序阻抗模型,深入剖析逆变器在弱电网环境中的动态响应特性,结合锁相环、电流环等关键控制环节对系统阻抗的影响机制,采用序阻抗稳定性判据评估多机并网或复杂电网条件下的系统稳定裕度。研究在Simulink平台中实现激励信号注入、频率响应采集与阻抗曲线绘制,为高比例新能源接入背景下并网系统的稳定性分析提供了可靠的仿真手段与理论支撑,尤其适用于SCI级别论文成果的复现与拓展验证。; 适合人群:电力电子、新能源并网技术及相关领域的硕士/博士研究生、科研人员,以及从事光伏逆变器、微电网稳定控制开发的工程技术人员。; 使用场景及目标:①掌握扫频法在电力电子装置阻抗建模中的具体实施流程;②理解并应用基于序阻抗的稳定性判据进行系统稳定边界分析;③用于高水平学术论文(如SCI期刊)中阻抗建模与稳定性分析部分的仿真复现与方法验证; 阅读建议:建议读者结合文中所述方法与提供的参考文献,自主搭建Simulink仿真模型,逐步完成扰动信号设计、数据采集、傅里叶分析及阻抗拟合全过程,深入探究控制参数变化对系统阻抗特性和稳定性的具体影响,强化理论与实践的融合能力。


数据库相关
