Delphi

How to force a focus on a component before the Form is shown

眉间皱痕 提交于 2019-12-30 18:27:22
问题 I have to show (with showModal) a Form with many TEdit but I want to force the focus on a TEdit, but not always the same, depending on the context. I can't use SetFocus before the ShowModal (because the Form is not activate) and use the Component Name or Tag is not convenient in my application. Do you have an idea ? 回答1: The simplest way to achieve your goal, in my view, is to assign to the ActiveControl property for the form. You can do this before showing the form. When you form is later

How to force a focus on a component before the Form is shown

给你一囗甜甜゛ 提交于 2019-12-30 18:27:11
问题 I have to show (with showModal) a Form with many TEdit but I want to force the focus on a TEdit, but not always the same, depending on the context. I can't use SetFocus before the ShowModal (because the Form is not activate) and use the Component Name or Tag is not convenient in my application. Do you have an idea ? 回答1: The simplest way to achieve your goal, in my view, is to assign to the ActiveControl property for the form. You can do this before showing the form. When you form is later

Creating a new component by combining two controls (TEdit and TTrackBar) in Delphi VCL

假如想象 提交于 2019-12-30 18:24:08
问题 I am developing a Delphi 10.1 VCL application for Windows. For integer or float input I need a number input field which is connected with a slider. When the user changes the number in the input field the slider position changes accordingly. When the user changes the slider position the number in the number field is updated. I can solve this by using a TEdit and a TTrackBar and add the necessary update functionality in their OnChange event handlers. The problem is that I need many of such

string := const : why different implementation for local and result?

跟風遠走 提交于 2019-12-30 17:26:07
问题 In Delphi function result is frequently implemented as var-parameter (not out-parameter despite QC ticket). String constants are basically variables with negative refcounter, which should suppress automatic memory [de]allocation. http://docwiki.embarcadero.com/RADStudio/XE3/en/Internal_Data_Formats#Long_String_Types It really does suppress it: the code below does not leak. type TDealRecord = record id_Type: Integer; Price: extended; Remark: String; end; const const_loop = 100000000; function

Why does my class implement child interfaces, but not their parents?

孤街醉人 提交于 2019-12-30 17:25:32
问题 I found a (at least for me) unexpected behavior when using interface inheritance in Delphi. I have this simple class and interface hierarchy: +---------------+ | << IMyBase >> | +---------------+ ^ | +---------------+ | << IMyIntf >> | +---------------+ ^ | +---------+ | TMyObj | +---------+ I wanted to declare a variable of type IMyBase . Create a TMyObj and assign it to my variable. IHMO this is normal OOP practice. But it turned out that it does not compile. I Have also tried to declare a

Error to receive file on socket inside a thread

不打扰是莪最后的温柔 提交于 2019-12-30 15:45:17
问题 I'm having trouble to receive a byte array containg a PNG file. When the code is executed in OnClientRead event it works fine, already when transfered for a thread, happens an error of MemoryStream that says: Out of memory while expanding memory stream. At this point: if SD.State = ReadingSize then I want to know how to solve this specific trouble and also how can I check if I'm receiving a data that contains a file or a simple String ? The code: type TSock_Thread = class(TThread) private

Generate JSON array with LKJSON in Delphi 7

[亡魂溺海] 提交于 2019-12-30 14:37:34
问题 I want to produce something like this: { "nrVendas": 2, "totalVendas": 100.0, "vendas": [ { "nsuOrigem": "1", "data": "2014-03-14", "nrParcelas": 1, "valor": 50, "parcelas": [ { "numero": 1, "valor": 50 } ] }, { "nsuOrigem": "2", "data": "2014-03-14", "nrParcelas": 1, "valor": 50, "parcelas": [ { "numero": 1, "valor": 50 } ] } ] } I'm trying it this way: js3 := TlkJSONobject.Create; js3.Add('numero', '1'); js3.Add('valor', '50'); js32 := TlkJSONobject.Create; js32.Add('numero', '1'); js32.Add

Launch an EXE with elevated privileges from a “normal” non-elevated one?

只谈情不闲聊 提交于 2019-12-30 14:15:47
问题 I have an EXE running with normal privileges, but there are cases (for example using VSS / volume shadow copy) where I need admin privileges (if I'm not mistaken) The idea is to put the code that needs extra privileges in a separate EXE and launch it as needed. It's something that I'll rarely need, but I still need to have it as a last resort option (this is to say that I'll rarely need to call it, maybe once/twice a day on average) My question is: How can I call an admin-elevated process

Finding elements with XPath in Delphi

爱⌒轻易说出口 提交于 2019-12-30 13:45:55
问题 I am trying to find an element in an XML document in Delphi. I have this code, but it always says 0 elements in the log: function TForm1.KannaSidu: Boolean; var Doc: IXMLDOMDocument; List: IXMLDomNodeList; begin try Doc := CreateOleObject('Microsoft.XMLDOM') as IXMLDomDocument; Doc.async:=False; Doc.load(Filename); except LogTx('Error on page'); end; List:=Doc.selectNodes('/html/head'); LogTx(IntToStr(List.length)+' elements'); Result:=False; end; So how do I make XPath work? 回答1: In the

How to use GetSetProp and SetSetProp from TypInfo unit

喜夏-厌秋 提交于 2019-12-30 13:35:15
问题 I have a set of enumeration values that I need to convert to text and then back to a set. I believe that GetSetProp and SetSetProp from TypInfo unit would allow to do this but I have no idea on to get it to work. Any idea on how I can use GetSetProp and SetSetProp to accomplish this? type TSomething = (sOne, sTwo, sThree, sFour, s Five); TSomethings = set of TSomething; var Something: TSomethings; s: string; ... Something := [sOne, sThree]; s := GetSetProp(????); Something := []; // then use