event-handling

How can I dynamically inject code into event handlers in Delphi?

断了今生、忘了曾经 提交于 2019-11-27 18:25:35
问题 For debugging / performance tests I would like to dynamically add logging code to all event handlers of components of a given type at run time. For example, for all Datasets in a Datamodule, I need to run code in the BeforeOpen and AfterOpen events to capture the start time, and to log the elapsed time in AfterOpen. I would prefer to do this dynamically (no component subclassing), so that I can add this to all existing datamodules and forms with minimal effort only when needed. Iterating all

How do I make an eventhandler run asynchronously?

拟墨画扇 提交于 2019-11-27 17:36:45
I am writing a Visual C# program that executes a continuous loop of operations on a secondary thread. Occasionally when that thread finishes a task I want it to trigger an eventhandler. My program does that but the when the event handler is triggered, the secondary thread waits until the event handler is finished before continuing the thread. How do I make it continue? Here is the way I currently have it structured... class TestClass { private Thread SecondaryThread; public event EventHandler OperationFinished; public void StartMethod() { ... SecondaryThread.Start(); //start the secondary

Qt event loop and unit testing?

▼魔方 西西 提交于 2019-11-27 17:17:08
问题 I'we started experimenting with unit testing in Qt and would like to hear comments on a scenario that involves unit testing signals and slots. Here is an example: The code i would like to test is (m_socket is a pointer to QTcpSocket ): void CommunicationProtocol::connectToCamera() { m_socket->connectToHost(m_cameraIp,m_port); } Since that is an asynchronous call i can't test a returned value. I would however like to test if the response signal that the socket emits on a successful connection

Detect focus initiated by tab key?

旧街凉风 提交于 2019-11-27 17:06:35
问题 I want to detect the focus event of an element, but only if it was initiated by the user pressing the tab key. For example: <input type="text" id="foo" /> <input type="text" id="detect" /> If the user is focused on #foo and presses Tab , I want the event to fire once #detect becomes focused (or a conditional inside the focus event to be true). Conversely, if the user simply clicks on the #detect field to focus it, I do not want the event to fire (or I want the conditional inside the focus

How to work with delegates and event handler for user control

旧城冷巷雨未停 提交于 2019-11-27 16:33:59
问题 I have created a user control that contains a button. I am using this control on my winform which will be loaded at run time after fetching data from database. Now I need to remove a row from a datatable on the Click event of that button. The problem is that how do I capture that event in my form. Currently it goes in that user control's btn click event defination. 回答1: You can create your own delegate event by doing the following within your user control: public event UserControlClickHandler

Adding multiple onload handlers

你离开我真会死。 提交于 2019-11-27 15:51:02
I have two js files, each one with its own window.onload handler. Depending on how I attach the two onload handlers to the window object I get a different behaviour on the second handler. More specifically, here is my html file: <html> <head> <title>Welcome to our site</title> <script type="text/javascript" src="script1.js"> </script> <script type="text/javascript" src="script2.js"> </script> </head> <body id="pageBody"> <h2 align="center"> <a href="http://www.whatever.com" id="redirect"> Wellcome to our site... c'mon in! </a> </h2> </body> </html> It loads two js files, script1.js and script2

How can I post-process the data from an Excel web query when the query is complete?

ⅰ亾dé卋堺 提交于 2019-11-27 15:26:00
As a spreadsheet developer, I am trying to stitch together two sets of rows: one from a web query to a web service I own, and the other a set of manual rows added by the spreadsheet's user (not me). Excel's built in Web Query / Connections object only provides two modes: I can turn on "Enable background refresh" which makes the web query asynchronous, or uncheck it. With it unchecked, Excel freezes up while the query executes, which is undesireable. With it checked, there doesn't seem to be any kind of callback or event hook available to be notified, so that I can operate against the refreshed

C# Console App + Event Handling

為{幸葍}努か 提交于 2019-11-27 15:20:51
Hey all. I'm trying to see about handling events in a console application. I would prefer to not use silent WinForms (though I understand that that's one way) to do it. I've read over a similar question and its response. See response text below ( link ): The basic requirement of an STA thread is that it needs to run a message pump. In Windows Forms, you can use Application.Run. Or you could write the message pump by hand, using user32!GetMessage & DispatchMessage. But it's probably easier to use the one in WinForms or WPF. What the basic structure of a program that uses "user32 -> GetMessage"

C# Cancel Windows Shutdown

点点圈 提交于 2019-11-27 15:20:35
i want to my application can prevents from windows shut down. i know that there is a system command to do that. but don't work for my program. i use this code for "cancel" the windows shut down: private void Form1_FormClosing(object sender, FormClosingEventArgs e) { if (e.CloseReason.Equals(CloseReason.WindowsShutDown)) { MessageBox.Show("Cancelling Windows shutdown"); string cmd = "shutdown /a"; Process.Start(cmd);// for executing system command. } } and also use this code, but does not work :( : public Form1() { InitializeComponent(); SystemEvents.SessionEnding += SessionEndingEvtHandler; }

How to map Qt Signal to Event in Managed C++ (C++/CLI)

柔情痞子 提交于 2019-11-27 15:18:33
问题 I'm writing a wrapper in .NET (C++/CLI) to be able to use some native C++ Qt code in .NET. How can I map a Qt signal into a managed .NET event, so that when my Qt code fires off a signal, I can bring this forward to the .NET code. My Managed class defines the event, but if I try to use the normal QObject::connect method to hook up to the signal, it requires a QObject * receiver... I guess I have to do some magic marshalling of some sorts? 回答1: Define normal unmanaged Qt event handler. From