一个消息传递参数问题 ( 积分: 50 )

  • 主题发起人 主题发起人 新来的菜鸟
  • 开始时间 开始时间

新来的菜鸟

Unregistered / Unconfirmed
GUEST, unregistred user!
我用一个exe主文件调用dll子窗体,然后用dll子窗体向主窗体传递消息的方式传递参数为何主窗体接收不到,请各位大哥帮看看,谢谢!
dll代码
unit DLLFormUnit;

interface

uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, Menus, StdCtrls, ExtCtrls, DB, ADODB, Grids, DBGrids;

type
basemsg=packed Record
userid:string;
end;
//這裡定義消息,建議再開一個單元,存放此類常量
const
WM_ModifyAA = WM_USER + 100;
type
TfrmDLLForm = class(TForm)
Label1: TLabel;
Button1: TButton;
procedure FormClose(Sender: TObject; var Action: TCloseAction);
procedure Button1Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;

var

implementation

uses Unit1;

{$R *.dfm}


procedure TfrmDLLForm.Button1Click(Sender: TObject);
var
tmpStr:string;
begin
///在这我发送了一个消息,传递的变量为tmpStr:='sssss'
tmpStr:='sssss';
sendmessage(HWND_BROADCAST,wm_ModifyAA,0,Integer(tmpStr));
end;

end.

住窗体代码

unit Unit1;

interface

uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, Menus, Buttons, ComCtrls, ToolWin, ExtCtrls, StdCtrls;
type
basemsg=packed Record
userid:string;
end;
//這裡定義消息
const
WM_ModifyAA = WM_USER + 100;
type
InvokeDLLForm = function(App: TApplication; Scr: TScreen): TForm;
TForm1 = class(TForm)
ToolBar1: TToolBar;
BitBtn1: TSpeedButton;
BitBtn2: TSpeedButton;
BitBtn3: TSpeedButton;
BitBtn4: TSpeedButton;
ToolButton3: TToolButton;
BitBtn5: TSpeedButton;
BitBtn6: TSpeedButton;
BitBtn7: TSpeedButton;
BitBtn8: TSpeedButton;
BitBtn9: TSpeedButton;
bitbtn11: TSpeedButton;
bitbtn12: TSpeedButton;
BitBtn10: TSpeedButton;
MainMenu1: TMainMenu;
N111: TMenuItem;
SBar: TStatusBar;
Timer1: TTimer;
N1: TMenuItem;
Image1: TImage;
N2: TMenuItem;
procedure BitBtn10Click(Sender: TObject);
procedure Timer1Timer(Sender: TObject);
procedure N1Click(Sender: TObject);
procedure N2Click(Sender: TObject);
procedure BitBtn1Click(Sender: TObject);
private
{ Private declarations }
//定义消息处理過程
procedure WMModifyAA(var msg: TMessage);message WM_ModifyAA;
public
{ Public declarations }
end;

var
Form1: TForm1;
DLLForm: TForm;
Windowsid:integer;
aa:string;
implementation


{$R *.dfm}
//實現示例
procedure TForm1.WMModifyAA(var msg: TMessage);
begin
显示出传递的变量
aa:=PChar(msg.LParam);
showmessage(aa);
end;
end;

end.
我的目的就是通过dll子窗体发送消息改变主窗体的全局变量aa,为何不成功,请高手告知谢谢
 
没人会吗?请高手指点,谢谢
 
sendmessage(HWND_BROADCAST,wm_ModifyAA,0,Integer(pchar(tmpStr)));
 
to louqing_2
不行呀,还有没有其他的方法,等待中...
 
等待中....
 
把tmpStr也搞成全局变量试试
 
to lake_cx
tmpStr只是一个变量而已,我只是把这个变量传给主窗体而已,我觉得设不设成全局变量应该没关系吧!呵呵
 
自己搞定,哈哈
 

Similar threads

S
回复
0
查看
3K
SUNSTONE的Delphi笔记
S
S
回复
0
查看
2K
SUNSTONE的Delphi笔记
S
S
回复
0
查看
751
SUNSTONE的Delphi笔记
S
后退
顶部