delphi-2009

TThread.Synchronize causing (near) deadlock in Delphi 2009 (worked in Delphi 7)

一世执手 提交于 2019-12-01 08:46:20
In Delphi 2009, synchronize'd functions that worked fine in Delphi 7 execute with sublime slowness until you wiggle the mouse over the open form. Wiggling the mouse causes the program to go into some mouse idle state which does CheckSynchronize() . CheckSynchronize() appears to be called less frequently in Delphi 2009 than in Delphi 7, but we can't figure out why or where. Placing this code: procedure TMyForm.FormCreate(Sender : TObject) Classes.WakeMainThread := WakeMainThread; end; procedure TMyForm.WakeMainThread(Sender: TObject); begin SendMessage(Application.MainForm.Handle, WM_NULL, 0, 0

Generic TList<> in Delphi 2009 crash on IndexOf

故事扮演 提交于 2019-12-01 08:41:09
I've seen many mentions of bugs in Delphi 2009 generics, but never expected something so basic to fail in Update 3, no less. Calling IndexOf on a generic TList or TObjectList causes an access violation if the list contains 1 or more items: type TTest = class( TObject ); procedure DoTest; var list : TObjectList< TTest >; t : TTest; begin list := TObjectList< TTest >.Create; try t := TTest.Create; list.IndexOf( t ); // No items in list, correct result -1 list.Add( t ); list.IndexOf( t ); // Access violation here finally list.Free; end; end; The exception is "EAccessViolation: Access violation at

read streams line by line

我们两清 提交于 2019-12-01 08:27:56
Is there a way in Delphi to read streams ,line by line? Is there a way to set the encoding of the stream? I know of TEncoding.getEncodingPage(1250); How to get it from stream? I think you're looking for TStreamReader . You set the encoding in the constructor and then call ReadLine . In terms of how to get the encoding from the stream, that depends very much on what is in the stream, doesn't it? Delphi versions that lack TStreamReader can use Peter Below's StreamIO unit , which gives you AssignStream . It works just like AssignFile , but for streams instead of file names. Once you've used that

“As” operator for constrained generic types

Deadly 提交于 2019-12-01 06:50:28
问题 Consider: TTest <T : class, constructor> = class public function CreateMyObject : T; end; function TTest<T>.CreateMyObject : T; var Obj : TObject; begin Obj := T.Create; Result := (Obj as T); end; Why isn't this possible? Compiler yields an "Operator not applicable to this type" error message for the as operator. T is constrained to be a class type, so this should work, shouldn't it? Thanks for the help. 回答1: I ran into the same problem and solved it by adding a low-level pointer-copy method

Why I don't receive Exception if I use the object after I destroy it?

孤街醉人 提交于 2019-12-01 06:31:54
问题 The following code works just fine, but it shouldn't ! When I click the Button1, the object is destroyed first, and then its Value is used and I don't receive any Access Violation or something... Even more, the multiply operation gives the correct result, that proves that Obj1 is not destroyed ! But then again, this is not true either, because when I close the program it does'n report any memory leakage. I'm very confused. unit Unit1; interface uses Windows, Messages, SysUtils, Variants,

Is it possible to use WIndows Speech Recognition Engine in a word pronunciation game?

夙愿已清 提交于 2019-12-01 05:45:54
问题 I use to create an application that uses the windows speech recognition engine or the SAPI. its like a game for pronunciation that it give you score when you pronounce it correctly. but when i started experiments with SAPI, it has poor recognition unless if you load a grammar on it (XML) its give best recognition result. but the problem now is closest pronunciation from the input text will be recognize. for example: Database -> dedebase -> correct. even if you mispronounce it. it gives you

TThread.Synchronize causing (near) deadlock in Delphi 2009 (worked in Delphi 7)

笑着哭i 提交于 2019-12-01 05:41:58
问题 In Delphi 2009, synchronize'd functions that worked fine in Delphi 7 execute with sublime slowness until you wiggle the mouse over the open form. Wiggling the mouse causes the program to go into some mouse idle state which does CheckSynchronize() . CheckSynchronize() appears to be called less frequently in Delphi 2009 than in Delphi 7, but we can't figure out why or where. Placing this code: procedure TMyForm.FormCreate(Sender : TObject) Classes.WakeMainThread := WakeMainThread; end;

How to draw a custom border inside the non client area of a control with scroll bars?

不问归期 提交于 2019-12-01 05:14:54
I have a custom control with both scroll bars enabled and I want to draw a simple red line border around the client area and the scroll bars, like in the image below. How I do this ? This is the control code: unit SuperList; interface uses Windows, Controls, Graphics, Classes, Messages, SysUtils, StdCtrls; type TSuperList = class(TCustomControl) protected procedure Paint; override; procedure CreateParams(var Params: TCreateParams); override; public constructor Create(AOwner: TComponent); override; end; implementation procedure TSuperList.CreateParams(var Params: TCreateParams); begin inherited

3 points are collinear in 2d

风流意气都作罢 提交于 2019-12-01 04:12:07
I am trying to verify when 3 points (double) are collinear in 2-D. I have found different Pascal functions that return true if this is verified; those functions use integer to specify X and Y coordinates. I need a more precise calculation at least to the first 3 digits of the decimal part of X and Y expressed as double type. Who can help me with this? I found this function: function Collinear(x1, y1, x2, y2, x3, y3: Double): Boolean; begin Result := (((x2 - x1) * (y3 - y1) - (x3 - x1) * (y2 - y1)) = 0); end; But I guess the calculation would never be 0. Should I use something like that?

How to draw a custom border inside the non client area of a control with scroll bars?

陌路散爱 提交于 2019-12-01 01:59:04
问题 I have a custom control with both scroll bars enabled and I want to draw a simple red line border around the client area and the scroll bars, like in the image below. How I do this ? This is the control code: unit SuperList; interface uses Windows, Controls, Graphics, Classes, Messages, SysUtils, StdCtrls; type TSuperList = class(TCustomControl) protected procedure Paint; override; procedure CreateParams(var Params: TCreateParams); override; public constructor Create(AOwner: TComponent);