当前位置:主页>销售管理软件> 列表

关于多媒体定时器! 找进销存管理软件破解

进销存软件版1楼: 本人编写了一个软件,里面需要用到高精度定时器,最早采用QueryPerformanceFrequency
代码为
var
Start, L: TLargeInteger;
Freq: Integer;
begin
{ 取得频率, 并将单位转为 "次/每毫秒" }
QueryPerformanceFrequency(L);
Freq := Round(L / 1000);

bStopCounter := False;
{ 进入回圈前取得开始计数值 }
QueryPerformanceCounter(Start);
repeat
{ 不断取得目前计数值 }
QueryPerformanceCounter(L);

{ QuadPart 栏位是 Comp 型态, 因此可以直接进行加减乘除运算 }
//do something
{ 让讯息回圈处理讯息, 包括 WM_PAINT, 让 lblElapseTime 元件重绘 }
Application.ProcessMessages;
until bStopCounter or Application.Terminated;

后发现CPU资源达到70以上,后来发现多媒体定时器没有问题,也知道它是多线程的,所以编写代码为:
procedure TimerProc(uTimerID, uMessage: UINT; dwUser, dw1, dw2:
DWORD); stdcall;
begin
if time > 1000 then exit;
time:= mictime + 0.01;
end;
procedure MMTime(b: Boolean);
begin
if b then
TimerID := timeSetEvent(10, 0, @TimerProc, 0, 1)
else
timeKillEvent(TimerID);
end;

procedure TForm1.Button1Click(Sender: TObject);
begin
MMTime(False);
time := 0;
MMTime(True);
end;

后来程序不固定时间出现代码错误,说内存不可写,然后退出程序,在delphi里编译,出现提示什么“致命性错误”,尤其使用界面里的按钮和点击鼠标最为明显,大惑不解,至于分辨率也设过很多次,什么上限,下限的都设过,问题依旧,请高手明示一下怎样使用多媒体定时器最为适合,又或者有没有其他既占资源少,精确度又高的方法!

2楼: 帮你改一改你试试:
implementation
const
Stoplimit=1000;
var
time:Extended;
TimerID:LongWord;
procedure MMTime(b: Boolean);forward;
procedure TimerProc(uTimerID, uMessage: UINT; dwUser, dw1, dw2:DWORD); stdcall;
begin
if time > Stoplimit then
begin
MMTime(False);
exit;
end;
time:= time + 0.01;
end;

procedure MMTime(b: Boolean);
begin
if b then
TimerID := timeSetEvent(10, 0, @TimerProc, 0, 1)
else
if timeKillEvent(TimerID)=0 then TimerID:=0;
end;

procedure TimeBegin;
begin
if TimerID<>0 then MMTime(False);
TimerID:=0;
time:=0;
MMTime(True);
end;

测试调用:
procedure TForm1.ButtonClick(Sender: TObject);
begin
TimeBegin;
end;
修改理由是假设错误因重复按下按钮引起,故不要盲目杀死TimerID,改用判断决定TimerID的生死。
说实在话,都不知道你在做什么,看看没人回复,就顺手回复一次。 如进销存管理软件破解

3楼: 非常感谢回复,其实我的意图是显示秒表效果,当我按一下按钮秒表就会停,然后记下那个时间,这个秒表继续运行,我测试过纯简单窗口运行(一个Form,一个button,一个Edit1)没有发现问题,但我程序有好多个Timer,加上SkinData,里面还有很多控件,就发生问题,因重新开发非常困难,如何有效率地排除错误呢

4楼: 分段排除,也就是将一些没有关系的代码给注释了,然后运行,一个部分一个部分的来。

5楼: 出现的错误为两个窗口,一个为 "0x00401ee0" 指令引用的 "0x000001a" 内存。该内存不能为"written"。
另一个为 Invalid pointer operation
晕!~

6楼: 嘿嘿,不要指望我会告诉你任何知识,我在这个论坛是不说任何有价值的话的。

所以以下也是废话:
1.你真的把这样的代码作为共用代码来多处使用?
2.你真的使用一个EXIT做为暂停的手段?
3.你为什么不能写得更好些呢?
4.不要指望亡羊补牢的调试手段帮你解决所有问题!

进销存软件版7楼: 谢谢flamingo大哥的教诲。