关于TTimer 控件

Delphi中利用MSCOMM控件进行GPS数据采集 1、准备  GPS(Global Positioning System),即全球定位系统,利用24颗GPS卫星的测距和测时功能进行全球定位,在许多系统中,如机场导航系统,出租车辆管理和调度系统、江河流域的灾害信息管理和预测系统中,GPS得到了广泛的应用。本文利用MSCOMM控件实现了GPS数据的采集,可为信息管理和指挥调度等提供定位数据。  本文采用GPS的异步串行传送方式,将GARMIN 12C 阅读详情

近期写程序时用了TTimer控件,执行的代码如下:

var
pexe : pexetype;
i,j : integer;
url,ss : string;
begin
for i := 0 to monlist.Count - 1 do
begin
pexe := monlist[i];
if pexe.otherInfo = 0 then
continue;
url := 'http://localhost:' + inttostr(pexe.otherInfo) + '/test.php';
ss := '';
try
ss := idhttp1.Get(url);
except
sleep(1000);
if idhttp1.IOHandler <> nil then
idhttp1.IOHandler.Close;
try
ss := idhttp1.Get(url);
except
mysleep(1000);
if idhttp1.IOHandler <> nil then
idhttp1.IOHandler.Close;
try
ss := idhttp1.Get(url);
except
ss := '';
end;
end;
end;
if trim(ss) <> 'ok' then
begin
pexe.otherInfo := 0;
TMon.KillTask(pexe.pid);
log.log('killtask:'+pexe.path);
end;
end;

为了防止程序在sleep(1000)时处于假死状态,我把sleep(1000)用函数mysleep来代替,把1秒分解也10份,代码如下:

procedure mysleep(sec: integer);
var
i,j : integer;
begin
for i := 0 to sec - 1 do
begin
for j := 0 to 9 do
begin
sleep(100);
application.ProcessMessages;(让界面响应其他消息,如重画之类的,防止界面假死)
end;
end;
end;

问题就出来了,运行程序,一到mysleep(1) ,程序就不往下走了,又重新从Timer1Timer函数开始执行。为什么会这样,百思不得其解,后面看了TTimer的原码,才发现:

procedure TTimer.WndProc(var Msg: TMessage);
begin
with Msg do
if Msg = WM_TIMER then
try
Timer;
except
Application.HandleException(Self);
end
else
Result := DefWindowProc(FWindowHandle, Msg, wParam, lParam);
end;

对delphi而言,TTimer控件实际是一个消息定时发送器,每隔一个Interval就会定时发送类似WM_TIMER 的消息,当程序分发并获取这个消息时,就会处理Timer1Timer的事件。

那么原因找到了。application.ProcessMessages;这个函数是让程序处理其他消息,这样程序又从头开始了。

包括 indy 组件里的IdAntiFreeze控件也是通过application.ProcessMessages来实现的,所以如果Timer事件里有用到indy系列控件时,可能会出问题,如idhttp控件,在timer里用了,就不能放IdAntiFreeze控件了。

一般情况下,application.ProcessMessages 这个函数尽量要少用,因为他会影响消息的处理流程。如果要防止界面出现顿卡,最好的解决方法是用多线程来实现,把耗时的工作放到其他线程里来实现,而不全用来主线程里。

Delphi控件开发基础篇 Delphi控件开发基础篇 Delphi中控件(Component)是依托于 VCL(Visual Component Library)框架而出的。其根类是TComponent。 大凡控件都是从如下几个类继承得来。 TGraphicControl 在实际的界面开发工作中,有许多简单的控件,其本身仅仅是简单的显示一些提示信息,不会完成什么复杂的工作,譬如 TLabel,TPaintBox等控件;... 阅读详情

相关推荐

delphi 几个定时器方法的比较

使用delphi比较了系统定时器,setevevt函数,多媒体定时器技术定时的时间差,并将多媒体定时器封装成类

TTimer内部工作原理

<br />如果使用传统的SDK开发方式,那么,创建和销毁一个定时器有两个API可以使用:<br />UINT_PTR SetTimer(<br />  HWND hWnd,              // handle to window, 用来接收WM_TIMER消息的窗体句柄<br />  UINT_PTR nIDEvent,      // timer identifier, 定时器的ID<br />  UINT uElapse,           // time-out value, 定时器的超

zyyjc的专栏 4951

Delphi通过多个Timer控件执行多任务..rar

Delphi通过多个Timer控件执行多任务..rar

delphi 定时器的简单应用-TTimer控件

delphi 定时器的简单应用-TTimer控件

菜鸟小扎 1万+

Delphi使用CreateAnonymousThreadX传递参数的匿名线程

delphi的CreateAnonymousThreadX传递参数的匿名线程

TThreadTimer_DelphiXE8多线程_多线程_

delphi多线程实例

delphi android 定时器,Delphi定时器控件TTimer“一睡不醒”问题研究

1,试验1—基础代码1.1页面控件与代码定时器appTimer1函数Timer_workspaInterval线程1000code1500ormEnabledblogTrue事件TrueciOntimer事件itif Timer1.Tag=1 then exit; //tag=1表示正在忙Timer1.Tag := 1;trymemo1.Lines.Add(formatDatetime('NN:...

weixin_29607629的博客 590

开源AI数字人DUIX:从零构建你的智能交互助手

本文详细介绍了如何利用开源AI数字人DUIX从零构建智能交互助手。文章阐述了DUIX作为开源项目的核心优势,包括低成本启动、低网络依赖和高度可定制性,并提供了从开发环境搭建、核心模块(AI模型、语音、形象)配置到个性化业务逻辑开发与最终部署的完整实践指南,帮助开发者快速掌握构建专属AI数字人的全流程。

weixin_29051811的博客 504

delphi 中几种多线程操作方式

因为使用 TThread 建立线程时会同时分配更多资源(譬如你自定义的成员、还有它的祖先类(TObject)分配的资源等等), 如果用 ExitThread 给草草退出了, 这些资源将得不到释放而导致内存泄露. 尽管 Delphi 提供了 EndThread(其内部调用 ExitThread), 这也不需要我们手动操作(假如非要手动操作也是件很麻烦的事情, 因为很多时候你不知道线程是什么时候执行完毕的).线程在等待时, 其中的计数也还在增加. 这也就是说: 现在并没有去处理线程的同步;

5815

【可不卸载重装】VS2019新建项目里没有CUDA选项

问题:VS2019 新建项目里没有CUDA选项,vs也属性没有cuda。这是因为你在Visual Studio 2019安装之前,先安装了CUDA Toolkit。

qq_62844901的博客 1318

欧姆龙 CJ1W-SCU模块使用通配符+结束码实现非固定长度数据的接收

实验设备:CJ2M-CPU33、CJ1W-SCU21、XW2Z-200T 实验目的:了解 CJ1W-SCU 通配符使用 1.硬件接线: CJ1W-SCU21单元号拨码置于8,使用串口1(232口)。 2.软件设置: ① 新建工程,选择PLC型号CJ2M-CPU33,切换到编程模式,如下图: 、 ② 创建I/O并进行相关配置,如下图: ③ 设置为用户设置,协议宏模式,8位数据位,2位停止位,偶校验9600波特率,如下图: 、 ④ 打开CX-Protocal软件,新建工程: .

weixin_42118352的博客 1984

Delphi定时器控件TTimer“一睡不醒”问题研究

1,试验1—基础代码 1.1页面控件与代码 定时器 Timer1 Timer_work Interval 1000 1500 Enabled True True Ontimer事件 if Timer1.Tag=1 then exit; ...

weixin_30825581的博客 674

SUMO仿真教程(5) —— 使用“XML“语言自定义构建路网

文章目录一.简要介绍1.node file2.edge file3.lane definitions(1)路段细分(2)邻近的对向车道(3)删除边或车道4.type file(1)简要概述(2)edge定义中引用type文件的示例(3)指定车辆种类的速度限制5.connections file(1)简要概述:(2)connection的属性参数(3)删除连接(4)设置连接的优先级(5)同一边的多个连接二.演示示例:1.自定义编写node file2.自定义编写edge file3.自定义编写type fil

weixin_50632459的博客 5015

C++Builder之ActiveControl

在Form上放置一个TTimer控件,编写TTimer对象响应事件。在Form上放置一些其他控件,在运行时更改活动控件显示位置,使活动控件每100毫秒向右移动一个像素。 void __fastcall TForm1::Timer1Timer(TObject *Sender) { Timer1->Interval = 100; if (ActiveControl) ActiveControl->Left = ActiveControl->Left + 1; } ..

1040

11、CUDA 内存优化:平铺矩阵乘法技术解析

本文深入解析了CUDA中的平铺矩阵乘法技术,重点介绍了如何利用共享内存和线程协作减少全局内存访问,提升计算效率。通过矩阵乘法实例,详细阐述了平铺算法的执行流程、内核代码实现及性能优化策略,包括平铺大小选择、线程同步机制和代码优化建议。文章还分析了该技术在深度学习、图像处理和科学计算等领域的应用价值,为CUDA程序的内存优化提供了系统性指导。

peace的博客 70

AUTOSAE软件配置-达芬奇( DaVinci Configurator)从新建工程开始

方法1,直接使用案例工程,一般SIP包会有一个创建好的案例工程,在这样的路径YOUR_SIP_DIR/Applications/SipAddon/StartApplication下面直接打开这个*.dpa文件即可看到已经预先做好的工程:但是,这个也不是全的,也不一定完全正确,至少MCAL是没有配置好的(MCAL是IC厂商提供的,并不归属SIP包的一部分)。这样就需要你自己去配置你想要的模块,修改里面的错误。

m0_49148264的博客 2937

c++ builder 学习(2) 定时器的使用

1 控件System 中的TTimer 打开定时器: Timer1->Enabled = true; 关闭定时器:       Timer1 ->Enabled = false; TTimer的InterVal属性设置定时器的时间 eg:实现字幕滚动 void __fastcall TForm2::FormPaint(TObject *Sender) { Label1

u010442009的专栏 3553

如何将 Fiori Elements Object Page Header 工具栏里按钮用 JavaScript 代码设置成禁用状态

本文介绍了如何在SAP Fiori Elements应用中动态控制Object Page工具栏按钮的可用状态。通过UI5 Inspector工具分析发现,这些按钮的enabled属性都双向绑定到/ui/enabled模型字段。在StatusExt.controller.js中,通过获取按钮ID前缀拼接完整控件ID,使用setEnabled(false)方法即可禁用按钮。关键点包括:1)使用extensionAPI获取视图ID前缀;2)注意事件回调中的this上下文绑定;3)通过修改模型字段可同步更新所有绑定

2007 年 ~ 2025 年,深耕 SAP 技术 18 年 370

Delphi - TTimer的源码

技术交流,DH讲解. 我之前用一个线程实现了Timer的功能,现在我们来看看Delphi自带的Timer怎么实现的? 其实,不看代码也大致知道怎么的? 1 SetTimer 和 KillTimer 2个API来控制Timer的启动和关闭 2 响应WM_Timer消息执行用户事件. 由于Timer是一个不可视控件,应该从TComponent继承,但是TComponent不具备...

weixin_34377919的博客 302

微信小程序 “net::ERR_CONNECTION_REFUSED” 报错大揭秘与破解之道

在微信小程序开发与运行过程中,“net::ERR_CONNECTION_REFUSED” 报错是开发者常遇难题。该错误意味着小程序与服务器连接建立失败,会导致功能无法使用、数据加载异常等问题,严重影响用户体验和业务运转。本文系统剖析此错误,从网络环境不佳、服务器异常、小程序配置有误等常见触发场景入手,提供网络、服务器、配置、代码等多维度排查步骤,给出针对性解决策略,如修复网络、处理服务器故障、修正配置与代码错误,还提出开发与运维阶段的预防措施,助力开发者高效解决该报错问题。

邓邓子的博客 6132

SAP B1中文培訓教材_SDK

公司内部培训资料,对开发工具 ,DIAPI, UIAPI,Add-ON有详细解说

ttimer 控件和 application.processmessages 导致的消息列表溢出。

procedure TForm1.tmr1Timer(Sender: TObject);begin  windows.Beep(100, 100);  windows.Beep(100, 100);  while true do  begin    Application.ProcessMessages;  end;end;这种代码会导致timer会被反复触发。procedure TForm1.tmr1Timer(Sender: TObject);begin  tmr1.enabled := false 

刘永锋的专栏 730

android 蓝牙通讯demo

android 下蓝牙通讯demo,实现了发现蓝牙,使能蓝牙,通过蓝牙发送消息。

Delphi中三种延时方法及其定时精度分析

Delphi中三种延时方法及其定时精度分析在Delphi中,通常可以用以下三种方法来实现程序的延时,即TTtimer控件,Sleep函数,GetTickCount函数。但是其精度是各不相同的。一、三种方法的简单介绍1)TTtimer控件  TTtimer控件的实质是调用Windows API定时函数SetTimer和KillTimer来实现的,并简化了对WM_TIMER 消息的处理

传的专栏 1860

ssm框架搭建

这个是一个在idea上成功跑起来的ssm框架项目,保存在这里方便以后使用直接下载

深度学习工具包 DeepLearningToolbox

深度学习工具包Deprecation notice.-----This toolbox is outdated and no longer maintained.There are much better tools available for deep learning than this toolbox, e.g. [Theano](http://deeplearning.net/software/theano/), [torch](http://torch.ch/) or [tensorflow](http://www.tensorflow.org/)I would suggest you use one of the tools mentioned above rather than use this toolbox.Best, Rasmus.DeepLearnToolbox================A Matlab toolbox for Deep Learning.Deep Learning is a new subfield of machine learning that focuses on learning deep hierarchical models of data.It is inspired by the human brain's apparent deep (layered, hierarchical) architecture.A good overview of the theory of Deep Learning theory is[Learning Deep Architectures for AI](http://www.iro.umontreal.ca/~bengioy/papers/ftml_book.pdf)For a more informal introduction, see the following videos by Geoffrey Hinton and Andrew Ng.* [The Next Generation of Neural Networks](http://www.youtube.com/watch?v=AyzOUbkUf3M) (Hinton, 2007)* [Recent Developments in Deep Learning](http://www.youtube.com/watch?v=VdIURAu1-aU) (Hinton, 2010)* [Unsupervised Feature Learning and Deep Learning](http://www.youtube.com/watch?v=ZmNOAtZIgIk) (Ng, 2011)If you use this toolbox in your research please cite [Prediction as a candidate for learning deep hierarchical models of data](http://www2.imm.dtu.dk/pubdb/views/publication_details.php?id=6284)```@MASTERSTHESIS\{IMM2012-06284, author = "R. B. Palm", title = "Prediction as a candidate for learning deep hierarchical models of data", year = "2012",}```Contact: rasmusbergpalm at gmail dot comDirectories included in the toolbox-----------------------------------`NN/` - A library for Feedforward Backpropagation Neural Networks`CNN/` - A library for Convolutional Neural Networks`DBN/` - A library for Deep Belief Networks`SAE/` - A library for Stacked Auto-Encoders`CAE/` - A library for Convolutional Auto-Encoders`util/` - Utility functions used by the libraries`data/` - Data used by the examples`tests/` - unit tests to verify toolbox is workingFor references on each library check REFS.mdSetup-----1. Download.2. addpath(genpath('DeepLearnToolbox'));Example: Deep Belief Network---------------------```matlabfunction test_example_DBNload mnist_uint8;train_x = double(train_x) / 255;test_x = double(test_x) / 255;train_y = double(train_y);test_y = double(test_y);%% ex1 train a 100 hidden unit RBM and visualize its weightsrand('state',0)dbn.sizes = [100];opts.numepochs = 1;opts.batchsize = 100;opts.momentum = 0;opts.alpha = 1;dbn = dbnsetup(dbn, train_x, opts);dbn = dbntrain(dbn, train_x, opts);figure; visualize(dbn.rbm{1}.W'); % Visualize the RBM weights%% ex2 train a 100-100 hidden unit DBN and use its weights to initialize a NNrand('state',0)%train dbndbn.sizes = [100 100];opts.numepochs = 1;opts.batchsize = 100;opts.momentum = 0;opts.alpha = 1;dbn = dbnsetup(dbn, train_x, opts);dbn = dbntrain(dbn, train_x, opts);%unfold dbn to nnnn = dbnunfoldtonn(dbn, 10);nn.activation_function = 'sigm';%train nnopts.numepochs = 1;opts.batchsize = 100;nn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.10, 'Too big error');```Example: Stacked Auto-Encoders---------------------```matlabfunction test_example_SAEload mnist_uint8;train_x = double(train_x)/255;test_x = double(test_x)/255;train_y = double(train_y);test_y = double(test_y);%% ex1 train a 100 hidden unit SDAE and use it to initialize a FFNN% Setup and train a stacked denoising autoencoder (SDAE)rand('state',0)sae = saesetup([784 100]);sae.ae{1}.activation_function = 'sigm';sae.ae{1}.learningRate = 1;sae.ae{1}.inputZeroMaskedFraction = 0.5;opts.numepochs = 1;opts.batchsize = 100;sae = saetrain(sae, train_x, opts);visualize(sae.ae{1}.W{1}(:,2:end)')% Use the SDAE to initialize a FFNNnn = nnsetup([784 100 10]);nn.activation_function = 'sigm';nn.learningRate = 1;nn.W{1} = sae.ae{1}.W{1};% Train the FFNNopts.numepochs = 1;opts.batchsize = 100;nn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.16, 'Too big error');```Example: Convolutional Neural Nets---------------------```matlabfunction test_example_CNNload mnist_uint8;train_x = double(reshape(train_x',28,28,60000))/255;test_x = double(reshape(test_x',28,28,10000))/255;train_y = double(train_y');test_y = double(test_y');%% ex1 Train a 6c-2s-12c-2s Convolutional neural network %will run 1 epoch in about 200 second and get around 11% error. %With 100 epochs you'll get around 1.2% errorrand('state',0)cnn.layers = { struct('type', 'i') %input layer struct('type', 'c', 'outputmaps', 6, 'kernelsize', 5) %convolution layer struct('type', 's', 'scale', 2) %sub sampling layer struct('type', 'c', 'outputmaps', 12, 'kernelsize', 5) %convolution layer struct('type', 's', 'scale', 2) %subsampling layer};cnn = cnnsetup(cnn, train_x, train_y);opts.alpha = 1;opts.batchsize = 50;opts.numepochs = 1;cnn = cnntrain(cnn, train_x, train_y, opts);[er, bad] = cnntest(cnn, test_x, test_y);%plot mean squared errorfigure; plot(cnn.rL);assert(er<0.12, 'Too big error');```Example: Neural Networks---------------------```matlabfunction test_example_NNload mnist_uint8;train_x = double(train_x) / 255;test_x = double(test_x) / 255;train_y = double(train_y);test_y = double(test_y);% normalize[train_x, mu, sigma] = zscore(train_x);test_x = normalize(test_x, mu, sigma);%% ex1 vanilla neural netrand('state',0)nn = nnsetup([784 100 10]);opts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samples[nn, L] = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.08, 'Too big error');%% ex2 neural net with L2 weight decayrand('state',0)nn = nnsetup([784 100 10]);nn.weightPenaltyL2 = 1e-4; % L2 weight decayopts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex3 neural net with dropoutrand('state',0)nn = nnsetup([784 100 10]);nn.dropoutFraction = 0.5; % Dropout fraction opts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex4 neural net with sigmoid activation functionrand('state',0)nn = nnsetup([784 100 10]);nn.activation_function = 'sigm'; % Sigmoid activation functionnn.learningRate = 1; % Sigm require a lower learning rateopts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex5 plotting functionalityrand('state',0)nn = nnsetup([784 20 10]);opts.numepochs = 5; % Number of full sweeps through datann.output = 'softmax'; % use softmax outputopts.batchsize = 1000; % Take a mean gradient step over this many samplesopts.plot = 1; % enable plottingnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex6 neural net with sigmoid activation and plotting of validation and training error% split training data into training and validation datavx = train_x(1:10000,:);tx = train_x(10001:end,:);vy = train_y(1:10000,:);ty = train_y(10001:end,:);rand('state',0)nn = nnsetup([784 20 10]); nn.output = 'softmax'; % use softmax outputopts.numepochs = 5; % Number of full sweeps through dataopts.batchsize = 1000; % Take a mean gradient step over this many samplesopts.plot = 1; % enable plottingnn = nntrain(nn, tx, ty, opts, vx, vy); % nntrain takes validation set as last two arguments (optionally)[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');```[![Bitdeli Badge](https://d2weczhvl823v0.cloudfront.net/rasmusbergpalm/deeplearntoolbox/trend.png)](https://bitdeli.com/free "Bitdeli Badge")

C++Builder:定时器Timer控件

C++builder

热爱是把一件事做到极致 2188

Delphi中实现程序的延时的方法

在Delphi中,通常可以用以下三种方法来实现程序的延时,即TTtimer控件,Sleep函数,GetTickCount函数。但是其精度是各不相同的。 一、三种方法的简单介绍1)TTtimer控件  TTtimer控件的实质是调用Windows API定时函数SetTimer和KillTimer来实现的,并简化了对WM_TIMER 消息的处理过程。通过设置OnTimer事件和Inter

pmj888666的专栏 3750

学会看VCL源码(一)

学会看VCL源码(一) finger 2009-03-16 12:45:13 回复 置顶 修改 删除 对于初学Delphi的人,一般只知道拖拖控件,写写一些事件代码,但如果要开始学会深入了解Delphi就要学会看VCL的源码,作为第一篇,我在这里介绍下最简单的TTimer控件的封装,从最简单的入手,可以让大家对VCL的封装先有个最基础的了解.下面进入正题,打开Delphi,拖一个TTi

fenger8293的专栏 3839

延时方法及其定时精度分析

Delphi中,通常可以用以下三种方法来实现程序的延时,即TTtimer控件,Sleep函数,GetTickCount函数。但是其精度是各不相同的。    一、三种方法的简单介绍    1)TTtimer控件    TTtimer控件的实质是调用Windows API定时函数SetTimer和KillTimer来实现的,并简化了对WM_TIMER 消息的处理过程。通过设置OnTimer事件和Int

熊出没危险 2129
上一篇: 一定要记住这20种PS技术!!!会让你的照片美的不行!!!
下一篇: GPRS的工作原理、主要特点
sdudubing
博客等级 码龄16年 117粉丝 25原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

当前余额3.43元 前往充值 >
需支付:10.00元
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付元
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值