Delphi

How to define a Type A in Type B and Type B in Type A?

五迷三道 提交于 2020-01-30 04:39:45
问题 I have two types. One Type A and one Type B. The Problem Type A contains Type B and Type B contains Type A. Such a thing like this won't work: type typeA = record test1 : typeB; end; type typeB = record test2 : typeA; end; Edit: Thats not my design. I converting C Header files (to access a DLL) that include such constructs to delphi. Edit2: "C++ structs are another name for classes AFAIR. And there must have been pointers, not values themselves. – Arioch 'The 1 min ago" Yes you are right that

How to define a Type A in Type B and Type B in Type A?

妖精的绣舞 提交于 2020-01-30 04:39:14
问题 I have two types. One Type A and one Type B. The Problem Type A contains Type B and Type B contains Type A. Such a thing like this won't work: type typeA = record test1 : typeB; end; type typeB = record test2 : typeA; end; Edit: Thats not my design. I converting C Header files (to access a DLL) that include such constructs to delphi. Edit2: "C++ structs are another name for classes AFAIR. And there must have been pointers, not values themselves. – Arioch 'The 1 min ago" Yes you are right that

Why Do Some Delphi Components Require “AOwner: TComponent” To Construct Them?

隐身守侯 提交于 2020-01-30 04:08:25
问题 It seems completely irrelevant to require a TComponent as an owner to instantiate an object of some kind. Why are there so many Delphi components that require this? For example, TXMLDocument requires a TComponent object to instantiate. Why is this and if there's a good reason, what should I be using in there to "do the right thing"? 回答1: The owner component is supposed to manage all its owned components. The owned components gets destroyed automatically when the owner is destroyed. This helps

Enable a TButton of an MDI ChildForm upon closing of another MDI ChildForm

送分小仙女□ 提交于 2020-01-30 03:29:45
问题 I have 2 MDI ChildForms and the Child1 has a TButton to open the Child2. I do not have any issue opening it at the same time disable the TButton to prevent Child2 from recreating again using TButton. Now, the challenge comes when I want the TButton of Child1 back to "enabled" when I closed the Child2. I am getting access error when doing these code: procedure TfrmChild2.FormClose(Sender: TObject; var Action: TCloseAction); begin child1_u.frmChild1.btnOpenChild2Form.Enabled := True; Action :=

Controlling file downloads

假装没事ソ 提交于 2020-01-29 09:49:07
问题 I am building an updater for my program with the use of a TWebBrowser. OnCreate the TWebBrowser navigates to the given URL. To download the update, the user is required to click a link. When the link is clicked this popup appears: So I was wondering if it was possible to: Bypass that popup and allow for automatic download. Set a fixed path that the file would download to. 回答1: I would use Indy's TIdHTTP component for that, eg: uses ..., IdHTTP; var Url, LocalFile: String; Strm: TFileStream;

Delphi desktop screenshot in Windows10, issue with GetDeviceCaps

北城以北 提交于 2020-01-29 08:45:25
问题 How can I get the correct screen size to take a screenshot in Windows10? it seems to get incorrect values (maybe DPI issue?) i.e // screenshot b := TBitmap.Create; DC := GetDC(GetDesktopWindow); try b.Width := GetDeviceCaps (DC, HORZRES) ; b.Height := GetDeviceCaps (DC, VERTRES) ; BitBlt(b.Canvas.Handle, 0, 0, b.Width, b.Height, DC, 0, 0, SRCCOPY) ; finally ReleaseDC (GetDesktopWindow, DC) ; end; on a 4K screen will only capture a small portion on the upper left corner. 回答1: You need to make

Delphi Exception Handling - How to clean up properly?

ぐ巨炮叔叔 提交于 2020-01-29 06:38:04
问题 I'm looking at some code in an application of ours and came across something a little odd from what I normally do. With exception handling and cleanup, we (as well as many other programmers out there, I'm sure) use a Try/Finally block embedded with a Try/Except block. Now I'm used to the Try/Except inside the Try/Finally like so: Try Try CouldCauseError(X); Except HandleError; end; Finally FreeAndNil(x); end; but this other block of code is reversed as so: Try Try CouldCauseError(X); Finally

How to get Delphi Currency Type to Round like Excel all the time?

为君一笑 提交于 2020-01-28 04:20:47
问题 I'm trying to get Delphi to Round like Excel but I can't. Here is the code: procedure TForm1.Button1Click(Sender: TObject); var s : string; c : currency; begin c := 54321.245; s := ''; s := s + Format('Variable: %m',[c]); s := s + chr(13); s := s + Format(' Literal: %m',[54321.245]); ShowMessage(s); end; I'm using a currency variable that is set to 54321.245 and when I format this variable it rounds using Bankers Rounding. However, when I format the same value as a literal it rounds the way

List of Delphi data types with 'thread-safe' read/write operations?

老子叫甜甜 提交于 2020-01-27 23:55:47
问题 Are 'boolean' variables thread-safe for reading and writing from any thread? I've seen some newsgroup references to say that they are. Are any other data types available? (Enumerated types, short ints perhaps?) It would be nice to have a list of all data types that can be safely read from any thread and another list that can also be safely written to in any thread without having to resort to various synchronization methods. 回答1: Please note that you can make essentially everything in delphi

List of Delphi data types with 'thread-safe' read/write operations?

可紊 提交于 2020-01-27 23:55:46
问题 Are 'boolean' variables thread-safe for reading and writing from any thread? I've seen some newsgroup references to say that they are. Are any other data types available? (Enumerated types, short ints perhaps?) It would be nice to have a list of all data types that can be safely read from any thread and another list that can also be safely written to in any thread without having to resort to various synchronization methods. 回答1: Please note that you can make essentially everything in delphi