程序有时候能运行,有时候不能运行!!!! 本帖最后由 tanglitao 于 2012-10-31 18:25:48 编辑 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 dll的入口点EntryPoint函数做了什么。是不是调用约定不一样。也许问题不在dll上。 终于找到根了,在DLL中,用了自己开发的组件(基于Panel)的,若不引用自定义的组件,就没有问题,能够正常执行,只要引用了自定义组件的单元,就会出现问题!在开发基于Panel的组件时,有什么注意事项吗? 在你的 Panel 组件程序中用 try 结构捕捉异常,如何? 通过dll调试吧dll项目的run菜单->paramaters->host application, 设置为可执行程序路径 断点调试一下看看,关闭时,是否释放了DLL或者你引用组件, 问题一直没有解决,现将VCL的代码贴出来,高手给指点一下:unit Panel_Guns;interfaceuses SysUtils, Classes, Controls, ExtCtrls, StdCtrls, Graphics, Messages, jpeg;const OPLock = WM_USER + 100; type TGunMess = procedure(DevCode, DataLen: byte; StatusData: TBytes) of object; TGun = class(TPanel) private FDevCode: integer; FRight: boolean; FDevName: ShortString; FGunType: ShortString; // 类型 FActive: boolean; // 是否为活动状态 FOnStatus: TGunMess; FGunCode: ShortString; FLockStatus_Chl: shortint; // 锁状态 FLockCon_Chl: shortint; // 开关通道 FHaveGun_Chl: shortint; // 检测 通道 FGunLong: shortint; // // FStatus_Chl: shortint; // 检测 通道 Image_Gun: TImage; // 显示图片 Image_Lock: TImage; // 显示锁的状态 // LGunCode: TLabel; // 显示号 // LGunLock: TLabel; // 信息显示 // Timer : TTimer; //在锁打开后,闪烁 procedure OpenLockMsg(var MSG: TMessage); message OPLock; procedure OpenLock(); procedure QueryStatus(); { Private declarations } protected procedure SetDevName(dName: ShortString); procedure Resize(Sender: TObject); procedure SetActive(Flag: boolean); procedure SetGunLong(GunLength: shortint); procedure SetGunCode(Code: ShortString); procedure DblClick(Sender: TObject); procedure DoDBClick(Sender: TObject); procedure OnTimer(Sender: TObject); { Protected declarations } public LockStatus, HaveGun: integer; constructor Create(AOwner: TComponent); override; destructor Destroy; override; procedure ProcessData(DataLen: integer; Datas: TBytes); { Public declarations } published property OnGunStatusChange: TGunMess read FOnStatus write FOnStatus; property Active: boolean read FActive Write SetActive; property DevName: ShortString read FDevName Write SetDevName; property DevCode: integer read FDevCode Write FDevCode; property GunCode: ShortString read FGunCode Write FGunCode; property HaveGun_Chl: shortint Read FHaveGun_Chl Write FHaveGun_Chl; property LockStatus_Chl : shortint Read FLockStatus_Chl write FLockStatus_Chl; property LockCon_Chl: shortint Read FLockCon_Chl write FLockCon_Chl; property OpenRight: boolean read FRight write FRight; property GunType: ShortString read FGunType write FGunType; property GunLongOrShort: shortint read FGunLong write SetGunLong; { Published declarations } end;procedure Register;implementationuses GunForm;procedure Register;begin RegisterComponents('Standard', [TGun]);end;constructor TGun.Create(AOwner: TComponent);begin inherited; color := $BCEE68; BevelOuter := bvNone; BevelKind := bkNone; width := 69; height := 109; Image_Gun := TImage.Create(self); Image_Gun.Parent := self; Image_Gun.Transparent := false; Image_Gun.AutoSize := false; Image_Gun.Center := false; Image_Gun.Align := alNone; Image_Gun.Left := -1000; Image_Gun.OnDblClick := DoDBClick; Image_Gun.Cursor := crHandPoint; Image_Gun.Stretch := true; Image_Gun.Proportional := true; Image_Gun.width := 67; Image_Gun.height := 47; Image_Lock := TImage.Create(self); Image_Lock.Parent := self; Image_Lock.Transparent := false; Image_Lock.AutoSize := false; Image_Lock.Center := false; Image_Lock.Align := alNone; Image_Lock.Left := -1000; Image_Lock.OnDblClick := DoDBClick; Image_Lock.Cursor := crHandPoint; Image_Lock.Stretch := true; Image_Lock.Proportional := true; Image_Lock.width := 67; Image_Lock.height := 60; FRight := false; FGunLong := 0; // end;destructor TGun.Destroy;begin if Image_Gun <> nil then // 2012-11-19 释放动态创建的 组件 begin Image_Gun.Free; Image_Gun := nil; end; if Image_Lock <> nil then begin Image_Lock.Free; Image_Lock := nil; end; inherited; if FGunControl <> nil then FGunControl.Free; FGunControl := nil;end;procedure TGun.OnTimer(Sender: TObject);begin { if LockStatus = 1 then begin LGunLock.Color := clBtnFace; end else begin if not (LGunLock.Color = clYellow) then LGunLock.Color := clYellow else LgunLock.Color := clGreen; end; }end;procedure TGun.OpenLockMsg(var MSG: TMessage);var d: TBytes; t: integer;begin case MSG.WParam of 0: OpenLock(); 1: QueryStatus(); 3: begin SetLength(d, 5); d[0] := $4F; d[1] := 1; d[2] := FLockCon_Chl; d[3] := 0; d[4] := $29; FOnStatus(FDevCode, 5, d); end; end;end;procedure TGun.QueryStatus(); // 发送查询状态命令var d: TBytes;begin SetLength(d, 4); d[0] := $4F; d[1] := 0; d[2] := FLockStatus_Chl; d[3] := $29; FOnStatus(FDevCode, 4, d); sleep(200); d[2] := FHaveGun_Chl; FOnStatus(FDevCode, 4, d);end;procedure TGun.OpenLock(); // 发送打开锁命令var d: TBytes; t: integer;begin SetLength(d, 5); d[0] := $4F; d[1] := 1; d[2] := FLockCon_Chl; d[3] := 0; // 闭合 d[4] := $29; FOnStatus(FDevCode, 5, d); { t := StrToInt(FGunControl.Ebacktime.Text); sleep(t); d[3] := 1; // 断开 FOnStatus(FDevCode, 5, d); } // 2012-6-17 注释end;procedure TGun.ProcessData(DataLen: integer; Datas: TBytes); // 推入要处理的数据var i: integer;begin if (Datas[0] = $AA) and (Datas[DataLen - 1] = $BB) then begin if Datas[1] = 2 then // 查询输入状态的 返回值 begin // Datas[3] = 0 '闭合 ,1- '断开'//通道闭合——锁开 if Datas[2] = FLockStatus_Chl then begin LockStatus := Datas[3]; if FGunControl = nil then FGunControl := TFGunControl.Create(nil); if LockStatus = 1 then begin { LGunLock.Font.color := $EE0000; LGunLock.Caption := '锁定'; } Image_Lock.Picture := FGunControl.Img_Lock.Picture; end else begin { LGunLock.Font.color := 255; LGunLock.Caption := ' 开启'; } Image_Lock.Picture := FGunControl.Img_unLock.Picture; end; end; if Datas[2] = FHaveGun_Chl then begin HaveGun := Datas[3]; Image_Gun.Picture.Assign(nil); Image_Gun.Update; if HaveGun = 1 then begin if FGunLong = 1 then // Image_Gun.Picture := FGunControl.Img_LongGun_N.Picture else Image_Gun.Picture := FGunControl.Img_ShortGun_N.Picture; end else begin if FGunLong = 0 then Image_Gun.Picture := FGunControl.Img_ShortGun_H.Picture else Image_Gun.Picture := FGunControl.Img_LongGun_H.Picture; end; end; end; if Datas[1] = 1 then // begin // Datas[2] -通道编号 , Datas[3] = 0 '闭合 ,1- '断开' if Datas[2] = FLockStatus_Chl then // 通道闭合——锁开 begin LockStatus := Datas[3]; if LockStatus = 1 then begin { LGunLock.Font.color := $EE0000; LGunLock.Caption := '锁定'; } Image_Lock.Picture := FGunControl.Img_Lock.Picture; end else begin { LGunLock.Font.color := 255; LGunLock.Caption := '开启'; } Image_Lock.Picture := FGunControl.Img_unLock.Picture; end; end; if Datas[2] = FHaveGun_Chl then begin HaveGun := Datas[3]; if HaveGun = 1 then // 没有 begin if FGunLong = 1 then // Image_Gun.Picture := FGunControl.Img_LongGun_N.Picture else Image_Gun.Picture := FGunControl.Img_ShortGun_N.Picture end else begin if FGunLong = 0 then Image_Gun.Picture := FGunControl.Img_ShortGun_H.Picture else Image_Gun.Picture := FGunControl.Img_LongGun_H.Picture end; end; end; // 上报的IO 输出状态 if Datas[1] = 3 then begin // Datas[2] -通道编号 ,Datas[3]-IO输出状态,0有输出,1-无输出 end; end;end;procedure TGun.DblClick(Sender: TObject);begin if FGunControl <> nil then begin FGunControl.pp := handle; // FGunControl.Show(); end; FGunControl.BopenLock.Enabled := FRight; FGunControl.Caption := ':' + FGunCode;end;procedure TGun.DoDBClick(Sender: TObject);begin DblClick(Sender);end;procedure TGun.Resize(Sender: TObject); // 重载改变大小beginend;procedure TGun.SetDevName(dName: ShortString); // 设置防区名称begin FDevName := dName;end;procedure TGun.SetGunLong(GunLength: shortint); // 设置长度begin FGunLong := GunLength; if FGunLong = 1 then begin height := 239; Image_Gun.height := 177; end else begin height := 109; Image_Gun.height := 47; end;end;procedure TGun.SetActive(Flag: boolean); // 设置活动状态begin FActive := Flag; if Flag = true then begin color := clGray; Image_Gun.AutoSize := false; // true; Image_Gun.Center := true; if FGunLong = 0 then Image_Gun.height := 47 else Image_Gun.height := 177; Image_Gun.Left := 0; Image_Gun.Top := 0; Image_Gun.Left := 1; Image_Lock.Left := 1; Image_Lock.Top := Image_Gun.height + 1; if FGunControl = nil then FGunControl := TFGunControl.Create(nil); FGunControl.pp := handle; end else begin Image_Gun.AutoSize := false; Image_Gun.Center := false; Image_Gun.Stretch := false; Image_Gun.Align := alNone; Image_Gun.Left := -1000; Image_Lock.Align := alNone; Image_Lock.Left := -1000; // LGunLock.Left := -1000; color := $BCEE68; end;end;procedure TGun.SetGunCode(Code: ShortString);begin FGunCode := Code; // LGunCode.Caption := Code;end;end. 说明:用上述代码做的组件,直接放到应用程序中,程序可以正常编译及运行;但是在DLL中form中引用该单元,应用程序在调用DLL时,即按F9运行时,程序有时候能正常启动,有时候不能启动(大部分如此);但“Run WithOut Debugging”没有问题;郁闷!!!! 终于找到原因了,在DLL或者VCL 中,不能饮用acPNG,至于为何,不知道,把所有图片改为了jpg格式,然后引用jpeg单元即可。 Delphi TWebBrowser刷新页面内容 dbexpress三层主从问题 麻烦大家帮帮我 如何左右调换字符串 如何在adodbgrid中隐藏当前行 Delphi程序的打包问题 数据类型转换问题 简单的Delphi问题,请各位大虾解答,谢谢! 有谁介绍什么好书给我? 怎样控制另一台机器上的进程/应用程序? 从系统导出的EXCEL文件无法用exce2010打开 Delphi 7中IdTCPServer和IdTCPClient使用疑问。
在开发基于Panel的组件时,有什么注意事项吗?
dll项目的run菜单->paramaters->host application, 设置为可执行程序路径
unit Panel_Guns;
interface
uses
SysUtils, Classes, Controls, ExtCtrls, StdCtrls, Graphics, Messages, jpeg;
const
OPLock = WM_USER + 100;
type
TGunMess = procedure(DevCode, DataLen: byte; StatusData: TBytes) of object;
TGun = class(TPanel)
private
FDevCode: integer;
FRight: boolean;
FDevName: ShortString;
FGunType: ShortString; // 类型
FActive: boolean; // 是否为活动状态
FOnStatus: TGunMess;
FGunCode: ShortString;
FLockStatus_Chl: shortint; // 锁状态
FLockCon_Chl: shortint; // 开关通道
FHaveGun_Chl: shortint; // 检测 通道
FGunLong: shortint; //
// FStatus_Chl: shortint; // 检测 通道
Image_Gun: TImage; // 显示图片
Image_Lock: TImage; // 显示锁的状态
// LGunCode: TLabel; // 显示号
// LGunLock: TLabel; // 信息显示
// Timer : TTimer; //在锁打开后,闪烁
procedure OpenLockMsg(var MSG: TMessage); message OPLock;
procedure OpenLock();
procedure QueryStatus();
{ Private declarations }
protected
procedure SetDevName(dName: ShortString);
procedure Resize(Sender: TObject);
procedure SetActive(Flag: boolean);
procedure SetGunLong(GunLength: shortint);
procedure SetGunCode(Code: ShortString);
procedure DblClick(Sender: TObject);
procedure DoDBClick(Sender: TObject);
procedure OnTimer(Sender: TObject);
{ Protected declarations }
public
LockStatus, HaveGun: integer;
constructor Create(AOwner: TComponent); override;
destructor Destroy; override;
procedure ProcessData(DataLen: integer; Datas: TBytes); { Public declarations }
published
property OnGunStatusChange: TGunMess read FOnStatus write FOnStatus;
property Active: boolean read FActive Write SetActive;
property DevName: ShortString read FDevName Write SetDevName;
property DevCode: integer read FDevCode Write FDevCode;
property GunCode: ShortString read FGunCode Write FGunCode;
property HaveGun_Chl: shortint Read FHaveGun_Chl Write FHaveGun_Chl;
property LockStatus_Chl
: shortint Read FLockStatus_Chl write FLockStatus_Chl;
property LockCon_Chl: shortint Read FLockCon_Chl write FLockCon_Chl;
property OpenRight: boolean read FRight write FRight;
property GunType: ShortString read FGunType write FGunType;
property GunLongOrShort: shortint read FGunLong write SetGunLong;
{ Published declarations }
end;procedure Register;implementationuses GunForm;procedure Register;
begin
RegisterComponents('Standard', [TGun]);
end;constructor TGun.Create(AOwner: TComponent);
begin
inherited;
color := $BCEE68;
BevelOuter := bvNone;
BevelKind := bkNone;
width := 69;
height := 109;
Image_Gun := TImage.Create(self);
Image_Gun.Parent := self;
Image_Gun.Transparent := false;
Image_Gun.AutoSize := false;
Image_Gun.Center := false;
Image_Gun.Align := alNone;
Image_Gun.Left := -1000;
Image_Gun.OnDblClick := DoDBClick;
Image_Gun.Cursor := crHandPoint;
Image_Gun.Stretch := true;
Image_Gun.Proportional := true;
Image_Gun.width := 67;
Image_Gun.height := 47;
Image_Lock := TImage.Create(self);
Image_Lock.Parent := self;
Image_Lock.Transparent := false;
Image_Lock.AutoSize := false;
Image_Lock.Center := false;
Image_Lock.Align := alNone;
Image_Lock.Left := -1000;
Image_Lock.OnDblClick := DoDBClick;
Image_Lock.Cursor := crHandPoint;
Image_Lock.Stretch := true;
Image_Lock.Proportional := true;
Image_Lock.width := 67;
Image_Lock.height := 60;
FRight := false;
FGunLong := 0; //
end;destructor TGun.Destroy;
begin if Image_Gun <> nil then // 2012-11-19 释放动态创建的 组件
begin
Image_Gun.Free;
Image_Gun := nil;
end;
if Image_Lock <> nil then
begin
Image_Lock.Free;
Image_Lock := nil;
end;
inherited; if FGunControl <> nil then
FGunControl.Free;
FGunControl := nil;end;procedure TGun.OnTimer(Sender: TObject);
begin
{ if LockStatus = 1 then
begin
LGunLock.Color := clBtnFace; end
else
begin
if not (LGunLock.Color = clYellow) then
LGunLock.Color := clYellow
else
LgunLock.Color := clGreen;
end; }
end;procedure TGun.OpenLockMsg(var MSG: TMessage);
var
d: TBytes;
t: integer;
begin
case MSG.WParam of
0:
OpenLock();
1:
QueryStatus();
3:
begin
SetLength(d, 5);
d[0] := $4F;
d[1] := 1;
d[2] := FLockCon_Chl;
d[3] := 0;
d[4] := $29;
FOnStatus(FDevCode, 5, d);
end;
end;end;procedure TGun.QueryStatus(); // 发送查询状态命令
var
d: TBytes;
begin
SetLength(d, 4);
d[0] := $4F;
d[1] := 0;
d[2] := FLockStatus_Chl;
d[3] := $29;
FOnStatus(FDevCode, 4, d);
sleep(200);
d[2] := FHaveGun_Chl;
FOnStatus(FDevCode, 4, d);
end;procedure TGun.OpenLock(); // 发送打开锁命令
var
d: TBytes;
t: integer;
begin
SetLength(d, 5);
d[0] := $4F;
d[1] := 1;
d[2] := FLockCon_Chl;
d[3] := 0; // 闭合
d[4] := $29;
FOnStatus(FDevCode, 5, d); { t := StrToInt(FGunControl.Ebacktime.Text);
sleep(t);
d[3] := 1; // 断开
FOnStatus(FDevCode, 5, d); } // 2012-6-17 注释end;procedure TGun.ProcessData(DataLen: integer; Datas: TBytes); // 推入要处理的数据
var
i: integer;
begin
if (Datas[0] = $AA) and (Datas[DataLen - 1] = $BB) then
begin
if Datas[1] = 2 then // 查询输入状态的 返回值
begin // Datas[3] = 0 '闭合 ,1- '断开'//通道闭合——锁开
if Datas[2] = FLockStatus_Chl then
begin
LockStatus := Datas[3];
if FGunControl = nil then
FGunControl := TFGunControl.Create(nil);
if LockStatus = 1 then
begin
{ LGunLock.Font.color := $EE0000;
LGunLock.Caption := '锁定'; }
Image_Lock.Picture := FGunControl.Img_Lock.Picture;
end
else
begin
{ LGunLock.Font.color := 255;
LGunLock.Caption := ' 开启'; }
Image_Lock.Picture := FGunControl.Img_unLock.Picture;
end;
end;
if Datas[2] = FHaveGun_Chl then
begin
HaveGun := Datas[3];
Image_Gun.Picture.Assign(nil);
Image_Gun.Update;
if HaveGun = 1 then
begin
if FGunLong = 1 then //
Image_Gun.Picture := FGunControl.Img_LongGun_N.Picture
else
Image_Gun.Picture := FGunControl.Img_ShortGun_N.Picture;
end
else
begin
if FGunLong = 0 then
Image_Gun.Picture := FGunControl.Img_ShortGun_H.Picture
else
Image_Gun.Picture := FGunControl.Img_LongGun_H.Picture;
end;
end;
end;
if Datas[1] = 1 then //
begin // Datas[2] -通道编号 , Datas[3] = 0 '闭合 ,1- '断开'
if Datas[2] = FLockStatus_Chl then // 通道闭合——锁开
begin
LockStatus := Datas[3];
if LockStatus = 1 then
begin
{ LGunLock.Font.color := $EE0000;
LGunLock.Caption := '锁定'; }
Image_Lock.Picture := FGunControl.Img_Lock.Picture;
end
else
begin
{ LGunLock.Font.color := 255;
LGunLock.Caption := '开启'; }
Image_Lock.Picture := FGunControl.Img_unLock.Picture;
end;
end;
if Datas[2] = FHaveGun_Chl then
begin
HaveGun := Datas[3];
if HaveGun = 1 then // 没有
begin
if FGunLong = 1 then //
Image_Gun.Picture := FGunControl.Img_LongGun_N.Picture
else
Image_Gun.Picture := FGunControl.Img_ShortGun_N.Picture
end
else
begin
if FGunLong = 0 then
Image_Gun.Picture := FGunControl.Img_ShortGun_H.Picture
else
Image_Gun.Picture := FGunControl.Img_LongGun_H.Picture
end;
end;
end;
// 上报的IO 输出状态
if Datas[1] = 3 then
begin // Datas[2] -通道编号 ,Datas[3]-IO输出状态,0有输出,1-无输出 end; end;end;procedure TGun.DblClick(Sender: TObject);
begin
if FGunControl <> nil then
begin
FGunControl.pp := handle; //
FGunControl.Show();
end;
FGunControl.BopenLock.Enabled := FRight; FGunControl.Caption := ':' + FGunCode;
end;procedure TGun.DoDBClick(Sender: TObject);
begin
DblClick(Sender);
end;procedure TGun.Resize(Sender: TObject); // 重载改变大小
beginend;procedure TGun.SetDevName(dName: ShortString); // 设置防区名称
begin
FDevName := dName;
end;procedure TGun.SetGunLong(GunLength: shortint); // 设置长度
begin
FGunLong := GunLength;
if FGunLong = 1 then
begin
height := 239;
Image_Gun.height := 177;
end
else
begin
height := 109;
Image_Gun.height := 47;
end;
end;procedure TGun.SetActive(Flag: boolean); // 设置活动状态
begin
FActive := Flag;
if Flag = true then
begin
color := clGray;
Image_Gun.AutoSize := false; // true;
Image_Gun.Center := true; if FGunLong = 0 then
Image_Gun.height := 47
else
Image_Gun.height := 177; Image_Gun.Left := 0;
Image_Gun.Top := 0;
Image_Gun.Left := 1;
Image_Lock.Left := 1; Image_Lock.Top := Image_Gun.height + 1;
if FGunControl = nil then
FGunControl := TFGunControl.Create(nil);
FGunControl.pp := handle;
end
else
begin
Image_Gun.AutoSize := false;
Image_Gun.Center := false;
Image_Gun.Stretch := false;
Image_Gun.Align := alNone;
Image_Gun.Left := -1000; Image_Lock.Align := alNone;
Image_Lock.Left := -1000;
// LGunLock.Left := -1000;
color := $BCEE68;
end;end;procedure TGun.SetGunCode(Code: ShortString);
begin
FGunCode := Code;
// LGunCode.Caption := Code;
end;end.