Delphi

How can Delphi records be initialized automatically?

爷,独闯天下 提交于 2020-06-25 08:37:15
问题 To initialize Delphi records I've always added a method (class or object) that would initialize to known good defaults. Delphi also allows for defining record "constructors" with parameters, but you cannot define your own parameter-less "constructor". TSomeRecord = record Value1: double; Value2: double; procedure Init; end; procedure TSomeRecord.Init; begin Value1 := MaxDouble; Value2 := Pi; end; Given the record above there is no warning that a record has not been initialized. Developers may

How can Delphi records be initialized automatically?

流过昼夜 提交于 2020-06-25 08:36:52
问题 To initialize Delphi records I've always added a method (class or object) that would initialize to known good defaults. Delphi also allows for defining record "constructors" with parameters, but you cannot define your own parameter-less "constructor". TSomeRecord = record Value1: double; Value2: double; procedure Init; end; procedure TSomeRecord.Init; begin Value1 := MaxDouble; Value2 := Pi; end; Given the record above there is no warning that a record has not been initialized. Developers may

How to safely Create and Free multiple objects in Delphi

和自甴很熟 提交于 2020-06-25 08:08:12
问题 How should you safely create and free multiple objects? Basically, this sort of thing: newOrderSource := TWebNewOrderSource.Create(); twData := TTWData.Create(); webData := TWebData.Create(); try //do stuff finally newOrderSource.Free(); twData.Free(); webData.Free(); end; In this case, the second and third create commands aren't safe, as they work with a database. Should I just put all the Creates in the try block and check if they are assigned before I call free on them? 回答1: You can do

Upgrade Indy library to use latest OpenSSL library

别来无恙 提交于 2020-06-25 05:40:29
问题 What is the process of upgrading Indy library written in Delphi to use the latest OpenSSL library having the newest features (eg. TLS v1.3)? The last version of Indy library I found uses libssl32.dll and ssleay32.dll DLLs. The latest OpenSSL library produces libssl-1_1.dll and libcrypto-1_1.dll DLLs. By changing the DLL names in Indy libray the dynamic loading of OpenSSL DLLs fails because many functions defined in Indy do not match the functions of OpenSSL DLLs. Thus OpenSSL API was changed.

How can I manually register an html-help file into the Delphi (RAD Studio) XE6 online documentation?

若如初见. 提交于 2020-06-24 13:44:05
问题 When a delphi component installer like the Developer Express components runs, it registers html-help files into the Delphi IDE, using h2reg and an INI file, and some macro-magic. If I was an open source or commercial author of a Delphi component, and I wanted to ship an installer that registers html-help, how would I do it? In very very old versions of Delphi (pre-2007) there was a tool for registering extra winhelp stuff. But in recent years, while many large vendors (like developer express)

Why would a module be unsavable until another module is loaded?

流过昼夜 提交于 2020-06-24 12:36:14
问题 Most of the units I work on rely on a Data Module. One of the most annoying things I come accross is an error message telling me Module X references another module and cannot be saved until Module Y is loaded. Now, I'm sure there is a very good reason why CheckNoFixups raises this error while trying to WriteRootStream , and fails to save what is in effect a Text file (and hopefully this isn't followed by Catastrophic Failure where I must then restart the IDE while still unable to save my work

How to remove focus from currently focused component?

╄→гoц情女王★ 提交于 2020-06-22 10:23:46
问题 I have a DB component which DataLink.UpdateRecord is called when it receives CM_EXIT message. This message is sent when it loses focus. When I click post button, it doesn't lose focus and value is not written to datasource. How can I reach an effect of component losing focus without switching it to other one? 回答1: You could use: procedure TCustomForm.DefocusControl(Control: TWinControl; Removing: Boolean); 回答2: We accomplish this by setting the Self.ActiveControl := nil. That causes all of

How to Open tables in EDIT/INSERT mode in Delphi

元气小坏坏 提交于 2020-06-18 12:10:38
问题 I tried to open my tables in Delphi with the following code: for I := 0 to Datamodule1.ComponentCount - 1 do if Datamodule1.Components[I] is TADOTable then Begin TADOTable(datamodule1.Components[i]).EDIT; End; But when I want to post it gives me an error that the tables is not in EDIT or INSERT mode. What have I done wrong here? 回答1: One sample of standard code is like this: // open the table ADOTable1.Open; // Mode = dsBrowse // Enter in Edit mode ADOTable1.Edit; //Mode = dsEdit // Change

How to Open tables in EDIT/INSERT mode in Delphi

孤街浪徒 提交于 2020-06-18 12:08:33
问题 I tried to open my tables in Delphi with the following code: for I := 0 to Datamodule1.ComponentCount - 1 do if Datamodule1.Components[I] is TADOTable then Begin TADOTable(datamodule1.Components[i]).EDIT; End; But when I want to post it gives me an error that the tables is not in EDIT or INSERT mode. What have I done wrong here? 回答1: One sample of standard code is like this: // open the table ADOTable1.Open; // Mode = dsBrowse // Enter in Edit mode ADOTable1.Edit; //Mode = dsEdit // Change

How to define a class with published method in a separate unit that is available at design-time to other units?

别来无恙 提交于 2020-06-17 09:15:25
问题 To overcome a bug in 10.3.3 (see QC report https://quality.embarcadero.com/browse/RSP-29565) relating to TFDTable detailed elsewhere (Delphi TFDTable open fails when indexname is set), I want to be able to define a class with a method in a common unit that can be assigned (programmatically) as a BeforeOpen event in the relevant DFM for TFDTable components defined on a Form or DataModule. I realize that this question has been asked before (e.g. How to make a separate unit for event methods,