高手请进,300分。一看就知道!(300分)

  • 主题发起人 主题发起人 antdown
  • 开始时间 开始时间
A

antdown

Unregistered / Unconfirmed
GUEST, unregistred user!
unit Unit1;

interface

uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls,MMSystem;

type
TForm1 = class(TForm)
Button1: TButton;
Button2: TButton;
procedure Button1Click(Sender: TObject);
procedure Button2Click(Sender: TObject);
procedure FormCreate(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;

type
TTest=class
private
dwTest:DWORD;
procedure CallBackTest(uTimerID, uMessage: UINT;
dwUser, dw1, dw2: DWORD) stdcall;
public
procedure Myproc;
end;
var
Form1: TForm1;
Test:TTest;
implementation

{$R *.dfm}

{ TTest }
procedure TForm1.Button1Click(Sender: TObject);
begin
Test:=TTest.Create;
Test.Myproc;
timeSetEvent(1000,1,@TTest.CallBackTest,1,1);
end;

procedure TTest.Myproc;
begin
dwTest:=1;
end;

procedure TTest.CallBackTest(uTimerID, uMessage: UINT; dwUser, dw1,dw2: DWORD);
begin
uTimerID:=dwTest;
OutputDebugString(PChar(IntToStr(uTimerID))); // 此行出错,虽然同在类内,但经过CALLBACK后,肯定发生了某些变化,请问如何读写dwTest
end;

procedure TForm1.Button2Click(Sender: TObject);
begin
Test.Free;
end;
 
不会吧!这种送份问题都解决不了?
 
问题结症在于多媒体时间触发器的调用上。不知道你设置TTest=class 还有其他什么用处。

修改你程序为如下,则不会出错。
……
type
TForm1 = class(TForm)
Button1: TButton;
Button2: TButton;
procedure Button1Click(Sender: TObject);
procedure Button2Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
……

procedure Test(uTimerID, uMessage: UINT; dwUser, dw1,dw2: DWORD);stdcall; //而是其后一定在跟上stdcall;不跟就出错
begin
uTimerID:=dwTest;
OutputDebugString(PChar(IntToStr(1))); // 不是此行出错,这里非常正确
end;

procedure TForm1.Button1Click(Sender: TObject);
begin
// Test:=TTest.Create;
// Test.Myproc;
timeSetEvent(1000,1,@Test,1,1); //调用@TTest.CallBackTest 或者TForm1.Test
end;说 //都将出错出错原因在于stdcall;

跟据这些你再改改吧!
 
后退
顶部