delphi-2009

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

强颜欢笑 提交于 2019-11-27 07:07:34
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 := TStringList.Create; end; procedure Test; var Clazz: TClass; Instance: TObject; begin Clazz := TMyClass; Instance := Clazz.Create; end; Use this: type TMyClass = class(TObject) MyStrings: TStrings; constructor Create; virtual; end; TMyClassClass = class of TMyClass; // <- add this

Unicode Console Application in Delphi 2009

北战南征 提交于 2019-11-27 06:04:17
问题 How can I create unicode console application with Delphi 2009? If I do like this: {$APPTYPE CONSOLE} uses SysUtils; begin writeln('öüğşç سيمانتت'); end. I get the following: ougsc ??????? 回答1: I'm not sure that is what you're after, but you can create Unicode console applications in all 32-bit Delphi versions by using the Windows API functions. I just tried with Delphi 4: program test; {$APPTYPE CONSOLE} uses Windows; var s: WideString; i: integer; Written: Cardinal; begin SetLength(s, 80);

Conditional behaviour based on concrete type for generic class

|▌冷眼眸甩不掉的悲伤 提交于 2019-11-27 04:37:03
问题 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? Pseudocode: TGenericType <T> = class function Func : Integer; end; ... function TGenericType <T>.Func : Integer; begin if (T = String) then Exit (0); if (T

Step by step upgrade of Indy 10 in Delphi 2009

試著忘記壹切 提交于 2019-11-27 04:25:43
Can someone help in telling the details on how to uninstall Indy 10 and install the latest build? I found it http://indy.fulgan.com/ZIP/IndyTiburon.zip There is a similar question , but not a satisfying answer, just some comments from the user who asked, but that is not a step by step guide. Why there is not a tool for this? Mark Robinson I did this very recently, I've done it before with 2007 and had lots of problems, but this time in D2010 it went really well... Assumptions: The Indy BPL's are stored in the bin folder DCP and DCU are stored in the lib\indy10 folder Source code is source\indy

Why is CharInSet faster than Case statement?

不羁的心 提交于 2019-11-27 04:25:26
问题 I'm perplexed. At CodeRage today, Marco Cantu said that CharInSet was slow and I should try a Case statement instead. I did so in my parser and then checked with AQTime what the speedup was. I found the Case statement to be much slower. 4,894,539 executions of: while not CharInSet (P^, [' ', #10,#13, #0]) do inc(P); was timed at 0.25 seconds. But the same number of executions of: while True do case P^ of ' ', #10, #13, #0: break; else inc(P); end; takes .16 seconds for the "while True", .80

Can I determine the order in which my units have been initialized?

杀马特。学长 韩版系。学妹 提交于 2019-11-27 03:55:20
问题 I am hunting a bug which might be connected to unit initialization order. Is there a way to see which initialization section was executed when? I need to know the order. This is during debugging, so I have the full power of the Delphi IDE, in my case Delphi 2009. I could set breakpoints, but this is rather tedious when having many units. Do you have any suggestions? 回答1: For units in the interface uses list, the initialization sections of the units used by a client are executed in the order

How to patch a method in Classes.pas

风格不统一 提交于 2019-11-27 03:37:07
问题 I need to patch a method in Classes.pas (TReader.ReadString - I want to force it to use a specified codepage, not the system default). If I copy Classes.pas into my project,I will end up having to rebuild the entire VCL. Is there any (easy) way to patch a method at runtime? 回答1: Modifying the implementation side of Classes.pas will not require recompiling everything. Delphi figures out if a unit needs to be recompiled by an algorithm that looks roughly like this: If DCU found: Is DCU format

How Can I Best Guess the Encoding when the BOM (Byte Order Mark) is Missing?

风流意气都作罢 提交于 2019-11-27 03:27:51
My program has to read files that use various encodings. They may be ANSI, UTF-8 or UTF-16 (big or little endian). When the BOM (Byte Order Mark) is there, I have no problem. I know if the file is UTF-8 or UTF-16 BE or LE. I wanted to assume when there was no BOM that the file was ANSI. But I have found that the files I am dealing with often are missing their BOM. Therefore no BOM may mean that the file is ANSI, UTF-8, UTF-16 BE or LE. When the file has no BOM, what would be the best way to scan some of the file and most accurately guess the type of encoding? I'd like to be right close to 100%

Hide the Main Form in a Delphi 2009 Application

淺唱寂寞╮ 提交于 2019-11-27 02:22:07
问题 The following code works fine in Delphi 7. However, in Delphi 2009 the form does remain hidden but the button on the taskbar is now appearing. ShowWindow(Handle, SW_HIDE); SetWindowLong(Handle, GWL_EXSTYLE, GetWindowLong(Handle, GWL_EXSTYLE) or WS_EX_TOOLWINDOW ); ShowWindow(Handle, SW_SHOW); The above code is called in the FormCreate method. 回答1: Turns out the reason we were seeing the Application window on the taskbar was a simple setting similar to stukelly's answer but not quite. To get

How to use external fonts?

淺唱寂寞╮ 提交于 2019-11-27 01:24:07
问题 Is it possible to use a font directly from resources in Delphi and how? I have a problem with the very first steps.Example I cannot include Segoe UI Light font in resources of a project,an exception occurs.And that is only if the file's extension is 'ttf'. If the written above is not possible then how do I use an external font without deploying the font separately(from executable)? Thanks in advance! 回答1: On Windows 2000 and later, you can use AddFontMemResourceEx to install fonts for your