tthread

Delphi XE5 - strange behavior help needed

拟墨画扇 提交于 2019-12-13 01:55:23
问题 I'm working on TLogger class that is logging my application logs to file... I have to way of getting Logs from File to TMemo: 1. assign TMemo to TLogger class then, assign True to DisplayInMemo property, then just call GetLogFromFile(); 2. call GetLogsFromFile(); then Self.Memo1.Text := TLogger.LogsResult; Below... Commented solution works fine... Uncommented solution works only every 2 click on button 4 procedure TForm1.Button4Click(Sender: TObject); // get log.file to memo begin //

Pausing execution of a Thread WITHOUT sleeping?

橙三吉。 提交于 2019-12-12 09:05:50
问题 I am using the Skype API, which sends back a message everytime it receives one. I am not sure if this really is what is causing it, but it's the closest I can get: When I send too many messages, the COM control can't handle all the replies, which causes it to crash the whole app. That happens when I use a for loop. I am using Threads to do the job, so my program won't hang. I know I can do Sleep(); in the thread, and will (should) not make the whole program sleep. The problem is though, that

When do I need synchronize in TThread?

寵の児 提交于 2019-12-10 09:40:54
问题 I know that you need synchronize (yourprocedure) to set e.g. a label's text. But what about: Reading a label's text. Toggle/Set the label's enabled property. Call other labels procedures/functions (e.g. onclick event). Is there an easy rule to know/remember when I need to use synchronize ? PS.: Is synchronize similar to PostMessage/SendMessage? 回答1: Easy rule of thumb: ANY access to VCL UI components needs to be synchronized. That includes both reading and writing of UI control properties.

Recreating a TThread Inside a TThread dervied class

拜拜、爱过 提交于 2019-12-08 14:00:20
问题 I created a new class derived from TThread class, and on the constructor i call "inherited Create(True);", and then call "Resume()" since i have override the Execute() call, now i wanna recall the Execute() (Run the Thread Again) without destroying the class instance, so i have a function inside the new class called "myRestart()", which recalls "inherited Create(True);" and makes me able to call "Resume()" again and thread works again. my question is, is this a safe practice? will it work

Can I raise an exception from within OnTerminate event of a TThread?

寵の児 提交于 2019-12-06 07:03:15
问题 I wrote a TThread descendant class that, if an exception is raised, saves exception's Class and Message in two private fields private //... FExceptionClass: ExceptClass; // --> Class of Exception FExceptionMessage: String; //... I thought I could raise a similar exception in the OnTerminate event, so that the main thread could handle it (here is a simplified version): procedure TMyThread.Execute; begin try DoSomething; raise Exception.Create('Thread Exception!!'); except on E:Exception do

Delphi TThread.CurrentThread and EAccessViolation - Is This a Bug or My Incompetence..?

橙三吉。 提交于 2019-12-05 18:30:27
问题 In Delphi 2009 I'm finding that any time I use TThread.CurrentThread in an application, I'll get an error message like the following when the application closes: Exception EAccessViolation in module ntdll.dll at 0003DBBA. Access violation at address 7799DBBA in module 'ntdll.dll'. Write of address 00000014. Unless it's just my machine, you can replicate this in a few seconds: create a new Delphi Forms Application, add a button to the form, and use something like the following for the button's

When do I need synchronize in TThread?

爱⌒轻易说出口 提交于 2019-12-05 12:27:05
I know that you need synchronize (yourprocedure) to set e.g. a label's text. But what about: Reading a label's text. Toggle/Set the label's enabled property. Call other labels procedures/functions (e.g. onclick event). Is there an easy rule to know/remember when I need to use synchronize ? PS.: Is synchronize similar to PostMessage/SendMessage? Easy rule of thumb: ANY access to VCL UI components needs to be synchronized. That includes both reading and writing of UI control properties. Win32 UIs , most notably dialogs like MessageBox() and TaskDialog() , can be used directly in worker threads

Using the Delphi XE7 Parallel Library

假装没事ソ 提交于 2019-12-04 14:21:35
问题 I have a time consuming routine which I'd like to process in parallel using Delphi XE7's new parallel library. Here is the single threaded version: procedure TTerritoryList.SetUpdating(const Value: boolean); var i, n: Integer; begin if (fUpdating <> Value) or not Value then begin fUpdating := Value; for i := 0 to Count - 1 do begin Territory[i].Updating := Value; // <<<<<< Time consuming routine if assigned(fOnCreateShapesProgress) then fOnCreateShapesProgress(Self, 'Reconfiguring ' +

Can I raise an exception from within OnTerminate event of a TThread?

佐手、 提交于 2019-12-04 13:13:59
I wrote a TThread descendant class that, if an exception is raised, saves exception's Class and Message in two private fields private //... FExceptionClass: ExceptClass; // --> Class of Exception FExceptionMessage: String; //... I thought I could raise a similar exception in the OnTerminate event, so that the main thread could handle it (here is a simplified version): procedure TMyThread.Execute; begin try DoSomething; raise Exception.Create('Thread Exception!!'); except on E:Exception do begin FExceptionClass := ExceptClass(E.ClassType); FExceptionMessage := E.Message; end; end; end;

What's wrong with using TThread.Resume? [duplicate]

倾然丶 夕夏残阳落幕 提交于 2019-12-04 10:20:08
问题 This question already has answers here : Resuming suspended thread in Delphi 2010? (2 answers) Closed 3 years ago . Long ago, when I started working with threads in Delphi, I was making threads start themselves by calling TThread.Resume at the end of their constructor, and still do, like so: constructor TMyThread.Create(const ASomeParam: String); begin inherited Create(True); try FSomeParam:= ASomeParam; //Initialize some stuff here... finally Resume; end; end; Since then, Resume has been