delphi-2009

How can I convert TBytes to RawByteString?

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 ...

Bug in Delphi 2009? -> *.res not found in project search path (works in Delphi 2006)

Hi, I have a problem migrating from Delphi 2006 to Delphi 2009. A Project which uses the JVCL complains that jvconsts.res is missing. The file is definitly there. The project search path includes the directory where the file is located. (Note: I don't have JVCL in my global search path to make it more portable) But the file should be f...

Organizing the search path

We create via "Tools | Options | Environment Variables" Variables like that: $(Sources) = D:\Sources\Delphi $(OurLib) = $(Sources)\OurLib\Src $(OurApp1) = $(Sources)\Applications\App1\3.x $(ThirdParty) = $(Sources)\ThirdPartyComponents We use these Variables in the project search path like that: ($OurApp1)\Src\Core;($OurApp1)\Src\GU...

Problem with setting Browsing Path in Delphi option page

Hi, I have a problem with setting Browsing Path in Delphi 2009: When I install a new component, I add DCU path to Delphi's Library Path, and source path to Delphi's Browsing Path. The application compiles fine, but holding Ctrl and clicking on any of the unit names for that component does not open the source file! It seems the only w...

HTML Doc Tool for Delphi 2009

Is there any free HTML creating documentation tool that fully understands Delphi 2009 features like generics and anonymous methods? I tried DelphiCodeToDoc but it crashes while parsing the source code. ...

How can I detect if a Delphi class has a virtual constructor?

For example, is there a way to find out that this class has a virtual constructor (at runtime)? TMyClass = class(TObject) MyStrings: TStrings; constructor Create; virtual; end; For example, in this code I would like to test if the class referenced by Clazz has a virtual constructor: procedure Test; var Clazz: TCl...

How can I create an Delphi object from a class reference and ensure constructor execution?

How can I create an instance of an object using a class reference, and ensure that the constructor is executed? In this code example, the constructor of TMyClass will not be called: type TMyClass = class(TObject) MyStrings: TStrings; constructor Create; virtual; end; constructor TMyClass.Create; begin MyStrings := ...

Pointer to generic type

In the process of transforming a given efficient pointer-based hash map implementation into a generic hash map implementation, I stumbled across the following problem: I have a class representing a hash node (the hash map implementation uses a binary tree) THashNode <KEY_TYPE, VALUE_TYPE> = class public Key : KEY_TYPE; Value ...

Derive from specialized generic types

Is it possible to derive a class from a specialized generic type: TGenericBase <T> = class // ... end; TSpecializedDerived = class (TGenericBase <String>) // ... end; Just wondering if this is possible at all... EDIT Code works fine when I put it in a new project. Must be due to some other mistake; sorry about that ...

Scope of anonymous methods

One nice thing about anonymous methods is that I can use variables that are local in the calling context. Is there any reason why this does not work for out-parameters and function results? function ReturnTwoStrings (out Str1 : String) : String; begin ExecuteProcedure (procedure begin Str1 := ...

Size of generic type

Is there any way to determine the size in bytes of something like TItem <T> = record Data : T; end; Can I write something like function TItem <T>.GetByteSize : Integer; begin if (T = String) then Result := GetStringByteSize (Data as String) else Result := SizeOf (Data); end; or perhaps with the help of specialization? functi...

Will Delphi be there in future ?

Yes, there is a version 2009. I know Delphi has a big community since years (10 plus)and I believe you could create native windows exe before Visual Basic got to speed (with all its dll's nighmare). But is it future-proof ? Is there a need or market for a non-crossplatform native all-in-one executable ? Will Embarcardero ex Codegear ex B...

Conditional behaviour based on concrete type for generic class

Since my question from yesterday was perhaps not completely clear and I did not get the answer I wanted, I will try to formulate it in a more general way: Is there a way to implement special behaviour based on the actual type of an instantiated generic type either using explict conditional statements or using some kind of specialization...

FxCop / StyleCop for Delphi?

Does anyone know of an equivalent to FxCop/StyleCop for Delphi? I would really like to get the automatic checking of style, etc. into Continuous Integration. ...

Delphi D2009 for Win32 and the CodeDom

Does anyone know whether it is possible (theoretically or in reality) to use the CodeDom that seems to be provided in Delphi's .NET counterpart? ...

D2009 problems with array of char - how can I `elegantly` fix my code?

Going through some of my older Delphi projects and upgrading them to D2009, as I find this version a great improvement (Generics.Collections - wow! ;)) to all previous releases, I encounter various problems. This one I managed to solve but the solution does not seem half as elegant as I believe it could be. (Note, I haven't written Delph...

'0.0' is not a valid timestamp when accessing OldValue of TClientDataSet's TDateField

When I use the following code in a newly inserted record in a TClientDataSet: cdsMyDateField.OldValue <> Null I get an EConvertError: ''0.0' is not a valid timestamp'. Looking at Delphi's VCL's code, it tries to convert the value to TDateTime which results in this Exception because the value (Null) is an invalid DateTime, but as I'...

{$IFOPT A4} ?

In Delphi 2009 (or older versions), how do you check the "Align" compile option in the code? The IFOPT directive seems to work only with pure switches ( {$IFOPT A4} does not compile ). I couldn't find an equivalent constant or such defined ( {$IF Align = 4} or such ) ...

Only run thread when I/O load is low

I have a background thread that performs I/O operations (keeping an index up to date). But in addition to that several clients access the server's hard disk and I want these accesses as fast as possible. So I thought, it would be nice, if the indexing thread is only running when the I/O load is low. Is there a way to figure this out? I...

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

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 ...