1.通过如下代码,我可以读取到数值1.00,但是如果不用try...except,虽然可以读取数值,但是同时回返回一个错误:access violation at。
所以我只好使用tryexcept把错误屏蔽掉,有没有更好的解决办法?这样会不会有问题?
unit Unit1;interfaceuses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms, Dialogs, StdCtrls, OleCtrls, SHDocVw, ComCtrls,mshtml, ExtCtrls,StrUtils;type
TForm1 = class(TForm)
WebBrowser1: TWebBrowser;
Button1: TButton;
Label1: TLabel;
Timer1: TTimer;
procedure Button1Click(Sender: TObject);
procedure Timer1Timer(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;var
Form1: TForm1;implementation{$R *.dfm}procedure TForm1.Button1Click(Sender: TObject);
var
strenth:real;begin
webbrowser1.Navigate('http://192.168.0.1:8080/xWebGateway.cgi');try
strenth:=strtofloat(midbstr(WebBrowser1.OleObject.Document.getElementByID('SignalStrength').innerhtml,31,length(WebBrowser1.OleObject.Document.getElementByID('SignalStrength').innerhtml)-41));
showmessage(floattostr(strenth));except
end;end;procedure TForm1.Timer1Timer(Sender: TObject);
begin
button1.Click;
end;end.
2.第二个问题是我在封装dll的时候碰到的,每次执行到 WebBrowser1:=tWebBrowser.Create(Form1);的时候就返回一个ole错误,搞了很久没有解决,还有这种做法能不能把值传回给调用这个dll的程序呢?代码如下
:
library CallStreng;{ 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,
StrUtils,
Unit1 in 'Unit1.pas' {Form1};exports
CallStreng_dll;begin
end.
unit Unit1;interfaceuses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls, OleCtrls, SHDocVw, ExtCtrls,OleServer, comobj, ActiveX,
MSHTML,StrUtils;
type
TForm1 = class(TForm)
private
{ Private declarations }
public
{ Public declarations }
end;
function CallStreng_dll():real;export; var
Form1: TForm1 ;
implementation
{$R *.dfm}
function CallStreng_dll():real;
var
WebBrowser1:TWebBrowser;
strenth:real;
begin
Form1 := TForm1.Create(nil); // 对应主窗体的定义
WebBrowser1:=tWebBrowser.Create(Form1);
// Form1.ShowModal;
webbrowser1.Navigate('http://192.168.0.1:8080/xWebGateway.cgi');
while WebBrowser1.Busy do
Application.ProcessMessages;
try
//showmessage('wqe');
begin
strenth:=strtofloat(midbstr(WebBrowser1.OleObject.Document.getElementByID('SignalStrength').innerhtml,31,length(WebBrowser1.OleObject.Document.getElementByID('SignalStrength').innerhtml)-41));
result :=strenth;
end;
except
end;
end;
end.
所以我只好使用tryexcept把错误屏蔽掉,有没有更好的解决办法?这样会不会有问题?
unit Unit1;interfaceuses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms, Dialogs, StdCtrls, OleCtrls, SHDocVw, ComCtrls,mshtml, ExtCtrls,StrUtils;type
TForm1 = class(TForm)
WebBrowser1: TWebBrowser;
Button1: TButton;
Label1: TLabel;
Timer1: TTimer;
procedure Button1Click(Sender: TObject);
procedure Timer1Timer(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;var
Form1: TForm1;implementation{$R *.dfm}procedure TForm1.Button1Click(Sender: TObject);
var
strenth:real;begin
webbrowser1.Navigate('http://192.168.0.1:8080/xWebGateway.cgi');try
strenth:=strtofloat(midbstr(WebBrowser1.OleObject.Document.getElementByID('SignalStrength').innerhtml,31,length(WebBrowser1.OleObject.Document.getElementByID('SignalStrength').innerhtml)-41));
showmessage(floattostr(strenth));except
end;end;procedure TForm1.Timer1Timer(Sender: TObject);
begin
button1.Click;
end;end.
2.第二个问题是我在封装dll的时候碰到的,每次执行到 WebBrowser1:=tWebBrowser.Create(Form1);的时候就返回一个ole错误,搞了很久没有解决,还有这种做法能不能把值传回给调用这个dll的程序呢?代码如下
:
library CallStreng;{ 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,
StrUtils,
Unit1 in 'Unit1.pas' {Form1};exports
CallStreng_dll;begin
end.
unit Unit1;interfaceuses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls, OleCtrls, SHDocVw, ExtCtrls,OleServer, comobj, ActiveX,
MSHTML,StrUtils;
type
TForm1 = class(TForm)
private
{ Private declarations }
public
{ Public declarations }
end;
function CallStreng_dll():real;export; var
Form1: TForm1 ;
implementation
{$R *.dfm}
function CallStreng_dll():real;
var
WebBrowser1:TWebBrowser;
strenth:real;
begin
Form1 := TForm1.Create(nil); // 对应主窗体的定义
WebBrowser1:=tWebBrowser.Create(Form1);
// Form1.ShowModal;
webbrowser1.Navigate('http://192.168.0.1:8080/xWebGateway.cgi');
while WebBrowser1.Busy do
Application.ProcessMessages;
try
//showmessage('wqe');
begin
strenth:=strtofloat(midbstr(WebBrowser1.OleObject.Document.getElementByID('SignalStrength').innerhtml,31,length(WebBrowser1.OleObject.Document.getElementByID('SignalStrength').innerhtml)-41));
result :=strenth;
end;
except
end;
end;
end.
解决方案 »
免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货