delphi-2010

When a class implements a descendant interface, why doesn't it automatically count as implementing the base interface?

ぃ、小莉子 提交于 2019-11-29 01:22:10
What's the reason this won't compile? type IInterfaceA = interface ['{44F93616-0161-4912-9D63-3E8AA140CA0D}'] procedure DoA; end; IInterfaceB = interface(IInterfaceA) ['{80CB6D35-E12F-462A-AAA9-E7C0F6FE0982}'] procedure DoB; end; TImplementsAB = class(TSingletonImplementation, IInterfaceB) procedure DoA; procedure DoB; end; var ImplementsAB: TImplementsAB; InterfaceA: IInterfaceA; InterfaceB: IInterfaceB; begin ImplementsAB := TImplementsAB.Create; InterfaceA := ImplementsAB; >> incompatible types ... end In contrast this is how I make it work: InterfaceA := ImplementsAB as InterfaceB; or

What is a safe Maximum Stack Size or How to measure use of stack?

五迷三道 提交于 2019-11-28 23:59:46
I have an app with a number of worker threads, one for each core. On a modern 8 core machine, I have 8 of these threads. My app loads a lot of plugins, which also have their own worker threads. Because the app uses huge blocks of memory (photos, eg. 200 MB) I have memory fragmentation problem. The problem is that every thread allocates the {$MAXSTACKSIZE ...} of address space. It's not using the physical memory but the adress space. I reduced the MAXSTACKSIZE from 1MB to 128KB and it seems to work, but I don't now if I'm near to the limit. Is there any possibility to measure how much stack is

How to get all of the supported file formats from Graphics unit?

妖精的绣舞 提交于 2019-11-28 23:16:23
When any TGraphic descendant registering its own graphic file format with a class procedure TPicture.RegisterFileFormat(), they're all stored in Graphics.FileFormats global variable. Too bad that FileFormats variable is not in the "interface" section of "Graphics.pas", so I can't access it. I need to read this variable to implement a special filter for my file-list control. Can I get that list without manual fixing the Graphics.pas's source code? Remy Lebeau You are working with a file-list control, and presumably thus a list of filenames. If you don't need to know the actual TGraphic class

Register custom form so I can inherit from it from multiple projects, without copying the form to the Object Repository folder

早过忘川 提交于 2019-11-28 21:57:52
I've got a custom frame I need to inherit from in multiple projects. This frame includes some code and some components, and it resides somewhere on disk, in it's own project directory. I don't want to COPY it to the Object Repository folder, that doesn't seem right to me: I'd end up having two copies of the form, one in my Mercurial-backed repository, one in Delphi's Object Repository. Absolutely not a good idea. What I want is to have my frame in a Package and have the Package do all that's required to make the frame known to the IDE and allow the IDE to create new siblings of the given frame

Method pointer and regular procedure incompatible

房东的猫 提交于 2019-11-28 21:33:39
I have an app, which has multiple forms. All these forms have a PopupMenu. I build the menu items programatically, all under a common root menu item. I want ALL the menu items to call the same procedure, and the menu item itself is basically acting as an argument.... I had this working when I just had one form doing this functionality. I now have multiple forms needing to do this. I am moving all my code to a common unit. Example. Form A has PopupMenu 1. When clicked, call code in Unit CommonUnit. Form B has PopupMenu 2. When clicked, call code in unit CommonUnit. When I need to call my popup

Resuming suspended thread in Delphi 2010?

醉酒当歌 提交于 2019-11-28 21:25:24
TThread's resume method is deprecated in D2010. So, I thought it should now work like this: TMyThread = class (TThread) protected Execute; override; public constructor Create; end; ... TMyThread.Create; begin inherited Create (True); ... Start; end; Unfortunately I get an exception "Cannot call start on a running or supsended thread"...which seems weird to me considering the fact that the documentation tells me that I should call Start on a thread created in suspended mode. What am I missing here? Jeroen Wiert Pluimers The reason is that a Thread is not supposed to start itself . The thread

How can I fix “Cannot open clipboard: Access Denied” errors?

一曲冷凌霜 提交于 2019-11-28 20:43:57
I am using the following code to copy text to the clipboard: Clipboard.Open; try Clipboard.AsText := GenerateClipboardText; finally Clipboard.Close; end; Seemingly at random I get "Cannot open clipboard: Access Denied" errors. I'm guessing that these errors are caused by other application locking the clipboard, but I never seem to be doing anything with other applications that should cause the locks. Strangely my users seem to be reporting more of the errors with Vista and Windows 7 than with XP. Is there a way to check if the clipboard is locked before trying to access it? This is not a

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

无人久伴 提交于 2019-11-28 20:13:36
问题 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

Ugly “disabled” images of TMainMenu

 ̄綄美尐妖づ 提交于 2019-11-28 19:20:00
问题 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

Is the compiler treatment of implicit interface variables documented?

耗尽温柔 提交于 2019-11-28 19:02:49
I asked a similar question about implicit interface variables not so long ago. The source of this question was a bug in my code due to me not being aware of the existence of an implicit interface variable created by the compiler. This variable was finalized when the procedure that owned it finished. This in turn caused a bug due to the lifetime of the variable being longer than I had anticipated. Now, I have a simple project to illustrate some interesting behaviour from the compiler: program ImplicitInterfaceLocals; {$APPTYPE CONSOLE} uses Classes; function Create: IInterface; begin Result :=