程序有时候能运行,有时候不能运行!!!!

tanglitao 2012-10-31 06:00:14
最近用Delphi2010 开发了一个小程序,包括:两个组件、一个Dll ,在Dll中动态创建几个组件,另外写了一个测试程序(projec1.exe),用于调用Dll ,但是,不知道怎么回事,在按F9 以后,程序启动半截,就没有反应了,需要在进程里强制结束project1.exe;然而,有时候就成功运行了,真是郁闷!需要说明的时候,编译出来的程序,可以单独正常执行!


在调试运行时,总是运行到这(运行信息):Module Load:srvcli.dll . No Debug Info. Base Address:$75670000. Process project1.exe ,程序就不往下执行了!!!


只要一调这个接口函数——即使函数什么都不做,就会有问题:
procedure DisPlay_Init(AppHandle, ParentForm: HWND; width, Height: integer;
Conn: PConn; ServerIP, RemotePort: ShortString); stdcall;
begin
{ if FrmDisplay = nil then
FrmDisplay := TFrmDisplay.Create(nil);
FrmDisplay.ParentWindow := ParentForm;
FrmDisplay.Left := 0;
FrmDisplay.Top := 0;
FrmDisplay.width := width;
FrmDisplay.Height := Height;
FrmDisplay.AppHWND := AppHandle;
FrmDisplay.Init(Conn, ServerIP, RemotePort);
FrmDisplay.Show; }
end;



...全文
529 10 打赏 收藏 转发到动态 举报
AI 作业
写回复
用AI写文章
10 条回复
切换为时间正序
请发表友善的回复…
发表回复
tanglitao 2013-08-05
  • 打赏
  • 举报
回复
终于找到原因了,在DLL或者VCL 中,不能饮用acPNG,至于为何,不知道,把所有图片改为了jpg格式,然后引用jpeg单元即可。
tanglitao 2013-08-01
  • 打赏
  • 举报
回复
说明:用上述代码做的组件,直接放到应用程序中,程序可以正常编译及运行;但是在DLL中form中引用该单元,应用程序在调用DLL时,即按F9运行时,程序有时候能正常启动,有时候不能启动(大部分如此);但“Run WithOut Debugging”没有问题;郁闷!!!!
tanglitao 2013-08-01
  • 打赏
  • 举报
回复
问题一直没有解决,现将VCL的代码贴出来,高手给指点一下: 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; implementation uses 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); // 重载改变大小 begin end; 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.
hhhfff2010 2013-03-15
  • 打赏
  • 举报
回复
断点调试一下看看,关闭时,是否释放了DLL或者你引用组件,
simonhehe 2013-03-15
  • 打赏
  • 举报
回复
通过dll调试吧 dll项目的run菜单->paramaters->host application, 设置为可执行程序路径
静_海 2013-03-15
  • 打赏
  • 举报
回复
在你的 Panel 组件程序中用 try 结构捕捉异常,如何?
tanglitao 2013-03-14
  • 打赏
  • 举报
回复
终于找到根了,在DLL中,用了自己开发的组件(基于Panel)的,若不引用自定义的组件,就没有问题,能够正常执行,只要引用了自定义组件的单元,就会出现问题! 在开发基于Panel的组件时,有什么注意事项吗?
bdmh 2012-11-07
  • 打赏
  • 举报
回复
调试dll,看看哪里出错
tanglitao 2012-11-07
  • 打赏
  • 举报
回复
冷门,自己顶一下
UnkownState 2012-11-01
  • 打赏
  • 举报
回复
dll的入口点EntryPoint函数做了什么。是不是调用约定不一样。也许问题不在dll上。

5,928

社区成员

发帖
与我相关
我的任务
社区描述
Delphi 开发及应用
社区管理员
  • VCL组件开发及应用社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧