delphi-2010

How to create an instance of object with RTTI in Delphi 2010?

人走茶凉 提交于 2019-11-30 02:01:53
As we all known, when we call a constructor of a class like this: instance := TSomeClass.Create; The Delphi compiler actually do the following things: Call the static NewInstance method to allocate memory and initialize the memory layout. Call the constructor method to perform the initialization of the class Call the AfterConstruction method It's simple and easy to understand. but I'm not very sure how the compiler handle exceptions in the second and the third step. It seems there are no explicit way to create an instance using a RTTI constructor method in D2010. so I wrote a simple function

Delphi XE3 EXE file size 25 times larger than Dephi 7

生来就可爱ヽ(ⅴ<●) 提交于 2019-11-30 00:26:45
As a test I decided to create a simple "Hello world" app in Delphi using Delphi 4, 5, 6, 7, 2005, 2010 and XE3. The app is nothing more than a TForm, a TButton with an OnClick event that calls ShowMessage('Hello world'). Below are the results of each final EXE with debugging turned off: Can someone explain why the XE3 version is 26 times larger than the average of the previous versions of Delphi? Here are my project settings for XE3: You may have done a only a compile after changing to 'Release' configuration. Try to do a rebuild (not recompile). This will truly activate the Release

How and when are variables referenced in Delphi's anonymous methods captured?

大兔子大兔子 提交于 2019-11-29 23:04:35
This was prompted by How to compare TFunc/TProc containing function/procedure of object? , specifically by David's comment to Barry's question. Since I don't have a Blog to post this to I'm going to ask this question here, and answer it. Question : When and how are variables referenced in Delphi's anonymous methods captured? Example: procedure ProcedureThatUsesAnonymousMethods; var V: string; F1: TFunc<string>; F2: TFunc<string>; begin F1 := function: string begin Result := V; // references local variable end V := '1'; F2 := function: string begin Result := V; end V := '2'; ShowMessage(F1);

Ugly “disabled” images of TMainMenu

十年热恋 提交于 2019-11-29 22:38:43
Delphi 2010, Win32 VCL. I need to create a main menu for my application with the most standard look. TMainMenu looks nice in all Windows versions, the only bad thing is when it displaying images for items with Enabled=False. Delphi has some strange method for building that disabled images (b/w extrusion with bevels, for me it looks like spew). I want to make a patch for that procedure in VCL sources and let menu to select disabled images from the same TImageList, but I can't find it. Is it exists at all or it is some standard windows API call? Do you know where is that procedure located? Sure

What is TMonitor in Delphi System unit good for?

自闭症网瘾萝莉.ら 提交于 2019-11-29 22:13:12
After reading the articles "Simmering Unicode, bring DPL to a boil" and "Simmering Unicode, bring DPL to a boil (Part 2)" of "The Oracle at Delphi" (Allen Bauer), Oracle is all I understand :) The article mentions Delphi Parallel Library (DPL), lock free data structures, mutual exclusion locks and condition variables (this Wikipedia article forwards to ' Monitor (synchronization) ', and then introduces the new TMonitor record type for thread synchronization and describes some of its methods. Are there introduction articles with examples which show when and how this Delphi record type can be

Use Indy to perform an IPv6 reverse DNS lookup

半城伤御伤魂 提交于 2019-11-29 22:07:26
问题 I am using Indy to perform a reverse IPv4 lookup using the following code. function ReverseDNSLookup(const IPAddress: String; const DNSServer: String; Timeout, Retries: Integer; var HostName: String): Boolean; var AIdDNSResolver: TIdDNSResolver; RetryCount: Integer; begin Result := FALSE; AIdDNSResolver := TIdDNSResolver.Create(nil); try AIdDNSResolver.QueryResult.Clear; AIdDNSResolver.WaitingTime := Timeout; AIdDNSResolver.QueryType := [qtPTR]; AIdDNSResolver.Host := DNSServer; RetryCount :=

How to “automatically” remove unused units from uses clause?

≡放荡痞女 提交于 2019-11-29 21:36:09
Does anyone know about a utility, that can automatically detect and remove unrequired units from the uses clause? Preferably it .. can be run against a unit and/or a project is free and works with Delphi 2010 Thanks in advance. RRUZ Try using the "Uses Unit Cleaner" Wizard from CnPack you can download from here Another option is use ICARUS . ICARUS is a small subset of Pascal Analyzer. It parses Delphi or Borland Pascal source code and generates a list of unneeded unit references in your uses lists alt text http://www.peganza.com/images/IcarusScreen.jpg ICARUS from Peganza does something

Which language elements can be annotated using attributes language feature of Delphi?

ⅰ亾dé卋堺 提交于 2019-11-29 21:23:29
Delphi 2010 introduced custom attributes which can be added to type declarations and methods. For which language elements can a custom attribute be used? The examples which I have found so far include class declarations, fields and methods. (And AFAIK generic classes do not support custom attributes). Some examples are shown in this article . It looks like variables (external to any class declaration) also can have attributes. Based on this article, attributes can be used for class and record fields and methods method parameters properties non-local enumeration declarations non-local variable

Generic method returning generic interface in Delphi 2010

非 Y 不嫁゛ 提交于 2019-11-29 19:42:57
问题 Given the code below, wich is a very trimmed down version of the actual code, I get the following error: [DCC Error] Unit3.pas(31): E2010 Incompatible types: 'IXList<Unit3.TXList<T>.FindAll.S>' and 'TXList<Unit3.TXList<T>.FindAll.S>' In the FindAll<S> function. I can't really see why since there is no problem with the previous very similar function. Can anyone shed some light on it? Is it me or is it a bug in the compiler? unit Unit3; interface uses Generics.Collections; type IXList<T> =

Delphi 2010 RTTI - RttiContext.FindType

你。 提交于 2019-11-29 15:36:46
With RttiContext.FindType('Classes.TStringList') I get RttiType of TStringList with no problem. But with RttiContext.FindType('MyUnit.TMyClass') I always get nil (of course MyUnit is in uses clause). Why, what is wrong? Example: unit MyUnit; interface uses Classes; type TMyClass = class(TStringList) end; implementation end. Main unit: ... uses MyUnit, ... var oCont: TRttiContext; oType: TRttiType; begin oCont := TRttiContext.Create; try oType := oCont.FindType('MyUnit.TMyClass'); <== oType = nil !! ... Daniele Teti Probably the class has not included by the delphi linker in the final