delphi-2009

Using the `in` keyword causes “E1012 Constant expression violates subrange bounds” in Delphi

怎甘沉沦 提交于 2019-12-05 13:08:00
问题 I've come across some rather unusual behaviour in a bit of Delphi code. When using the in keyword to check if an item is in a constant array, I get the following compilation error: E1012 Constant expression violates subrange bounds The constants are defined as follows: type TSomeEnum = (seFoo = 1000, seBar = 2000, seBoo = 3000, seFar = 4000, seFooBar = 5000, seBooFar = 6000, seLow = 1000, seHigh = 6000, seCount = 6); The line that is failing is the following: if someObj.someProperty in [seFoo

Max length for a dynamic array in Delphi?

帅比萌擦擦* 提交于 2019-12-05 10:50:06
I was curious how long a dynamic array could be so I tried SetLength(dynArray, High(Int64)); That has a value of 9,223,372,036,854,775,807 and I figure that would be the largest number of indexes I could reference anyway. It gave me a: ERangeError with message 'Range check error'. So I tried: SetLength(dynArray, MaxInt); and got the same error! Interestingly I could call it with SetLength(dynArray, Trunc(Power(2, 32)); Which is actually twice the size of MaxInt! I tried SetLength(dynArray, Trunc(Power(2, 63) - 1)); Which is the same as High(Int64), and that failed too. Short of continued trial

Delphi 2009 classes / components to read/write file permissions

◇◆丶佛笑我妖孽 提交于 2019-12-05 10:22:10
Does anyone have a set of classes / components that will work with Delphi 2009 (Unicode) to read and write NTFS file permissions? There was a thing called "NTSet" - but they stopped development at Delphi 2006 about 3 years ago :-( Any other takers?? Thanks! Marc JCL has units to deal with file permissions, and they claim D2009 compatibility. Colin Wilson's "NT low-level" component set wraps the APIs you need, and supports Delphi 2009 as well as earlier releases. However you may need to rely on the MS documentation and samples if you need detailed help to implement a specific operation. You can

How to start building a searchable garbage collector in Delphi (2009-2010)

a 夏天 提交于 2019-12-05 07:05:56
I'm looking for a way to control all business objects I create in my applications written in Delphi. As an article on Embarcadero's EDN ( http://edn.embarcadero.com/article/28217 ) states, there are basically three ways to do this. I'm mostly interested in the last one, using interfaces. That way, when the business object is no longer being referenced anywhere in the application, it will be dispose of memory wise (I'll get back on this part later). When creating a new business object, it would be wise to ask that new object manager whether I already fetched it earlier in the program, thus

Which lists could serve as temporary lists?

|▌冷眼眸甩不掉的悲伤 提交于 2019-12-05 04:51:53
When working with lists of items where the lists just serve as a temporary container - which list types would you recommend me to use? I don't want to destroy the list manually would like to use a built-in list type (no frameworks, libraries, ...) want generics Something which would make this possible without causing leaks: function GetListWithItems: ISomeList; begin Result := TSomeList.Create; // add items to list end; var Item: TSomeType; begin for Item in GetListWithItems do begin // do something end; end; What options do I have? This is about Delphi 2009 but for the sake of knowledge

Logging and Synchronization

情到浓时终转凉″ 提交于 2019-12-05 02:22:32
问题 I have just written my own logging framework (very lightweight, no need for a big logging framework). It consists of an interface ILogger and a number of classes implementing that interface. The one I have a question about is TGUILogger which takes a TStrings as the logging target and synchronizes the logging with the main thread so that the Items member of a listbox can be used as the target. type ILogger = Interface (IInterface) procedure Log (const LogString : String; LogLevel : TLogLevel)

TBitmap drawing transparent image in Delphi 2009

爷,独闯天下 提交于 2019-12-05 02:07:35
问题 Problem in drawing a semi transparent PNG image on TBitmap object. If the TBitmap's ,HandleType is set to bmDDB, then the canvas is drawn transparent. But the problem is it doesn't work on all kinds of machines (for ex: Windows on apple computers). When a TBitmap's HandleType property is set to bmDIB, canvas background is drawn white. bmp.HandleType := bmDIB; I tried setting Brush style to bsClear. But it draws the transparent pixels in black color. How can I draw an image preserving its

How in Delphi 2009 redirect console (stin, sterr)?

橙三吉。 提交于 2019-12-05 02:07:23
问题 I try several samples in the internet and none of them work - the scripts are not executed- (maybe because are for pre Delphi 2009 unicode?). I need to run some python scripts and pass arguments to them, like: python "..\Plugins\RunPlugin.py" -a login -u Test -p test And capture the output to a string & the errors to other. This is what I have now: procedure RunDosInMemo(DosApp:String; var OutData: String); var SA: TSecurityAttributes; SI: TStartupInfo; PI: TProcessInformation; StdOutPipeRead

Howto cast pointer to generic parameter type?

老子叫甜甜 提交于 2019-12-05 01:15:55
问题 it's my first question here, glad to have found this site. My question deals with the new Generics feature in Delphi 2009. Basically I tried to write a generic wrapper class for an existing hash map implementation. The existing implementation stores (String, Pointer) pairs, so in the wrapper class I have to cast between the generic parameter type T and the Pointer type and vice versa. type THashMap <T : class> = class private FHashList : THashList; ... end; I thought of a cast like this

How can I convert TBytes to RawByteString?

自闭症网瘾萝莉.ら 提交于 2019-12-05 00:35:33
问题 What is the best way to convert an array of bytes declared as TBytes to a RawByteString in Delphi 2009? This code actually works, maybe there is a faster way (without loop): function Convert(Bytes: TBytes): RawByteString; var I: Integer; begin SetLength(Result, Length(Bytes)); for I := 0 to ABytes - 1 do Result[I + 1] := AnsiChar(Bytes[I]); end; 回答1: You could consider using move (untested) function Convert(const Bytes: TBytes): RawByteString; begin SetLength(Result, Length(Bytes)); Move