Delphi

Working with large arrays - OutOfRam

♀尐吖头ヾ 提交于 2020-01-02 07:57:20
问题 I have an algorithm where I create two bi-dimensional arrays like this: TYPE TPtrMatrixLine = array of byte; TCurMatrixLine = array of integer; TPtrMatrix = array of TPtrMatrixLine; TCurMatrix = array of TCurMatrixLine; function x var PtrsMX: TPtrMatrix; CurMx : TCurMatrix; begin { Try to allocate RAM } SetLength(PtrsMX, RowNr+1, ColNr+1); SetLength(CurMx , RowNr+1, ColNr+1); for all rows do for all cols do FillMatrixWithData; <------- CPU intensive task. It could take up to 10-20 min end;

convert HH:MM:SS to seconds or minutes with delphi

北慕城南 提交于 2020-01-02 07:49:05
问题 Can someone advise me on the best way to convert a duration formated HH:MM:SS to seconds or minutes only? ie. 00:01:49 = 109secs I´m using this code but not work var i: real; j: integer; begin i := frac(real(StrToTime('00:00:01'))); j := trunc(frac(real(StrToTime('01:00:00'))) / i ); memo2.lines.add(inttostr(j)); when I try the code with 00:10:00 return 599 thanks 回答1: A very flexibel tool for handling durations is TTimeSpan found in unit System.TimeSpan. You can get the result in different

Delphi Indy https request with custom DNS resolving

痴心易碎 提交于 2020-01-02 07:37:27
问题 example url: https://api.binance.com/api/v1/time Using TIdDNSResolver and cloudflare dns I can get the host IP. direct request in the form of https://205.251.219.20/api/v1/time doesn't work cause as I understand the server expects to see "api.binance.com" in the url. (it doesnt work even in browser) Using synapce and the following patch to replace request's host with resolved IP I make it working function THTTPSend.InternalDoConnect(needssl: Boolean): Boolean; begin Result := False; FSock

Delphi: How to set text in TEdit/TMaskEdit without invoking the onchange event

与世无争的帅哥 提交于 2020-01-02 07:36:14
问题 I've got a pretty big setup form which I'd like to populate with data from a class. so I'm doing a lot of Edt1.text := ASettings.FirstThing; I'd like to avoid Edt1.onchange := nil; Edt1.text := ASettings.FirstThing; Edt1.onchange := edt1Onchange; How do I change the text in a text box and sidestep the onchange event. 回答1: I have used something like changing the OnChange handler, but more often, I use a flag. updatingFromCode := true; Edt1.Text := ASettings.FirstThing; updatingFromCode :=

JPEG Error #42 on assign

跟風遠走 提交于 2020-01-02 06:50:57
问题 Why can't I assign directly a MemoryStream to a Picture? Below I post two methods of assign a MemoryStream to a TImage. The Method1 doen't work and Method2 works. Why? Thanks Sam Method1 : This method returns an JPEG error #42 Var ms1 : TMemoryStream; J : TJPEGImage; St : String; begin ms1 := TMemoryStream.Create; try try St := 'somepath'; IdFTP1.Get(St, ms1); if ms1.Size > 0 then Begin J := TJPEGImage.Create; try J.LoadFromStream(ms1); Image4.Picture := nil; Image4.Picture.Assign(J); // here

How to calculate an area of a Windows region (HRGN) in pixels?

99封情书 提交于 2020-01-02 06:39:27
问题 What is the fastest way of getting the area of any arbitrary Windows region? I know I can enumerate all points of bounding rectangle and call the PtInRegion() function but it seems not very fast. Maybe you know some faster way? 回答1: When you call GetRegionData, you'll get a list of non-overlapping rectangles that make up the region. Add up their areas, something like this: function GetRegionArea(rgn: HRgn): Cardinal; var x: DWord; Data: PRgnData; Header: PRgnDataHeader; Rects: PRect; Width,

TMainMenu is not shown when the vcl styles is removed from the NC Area

你。 提交于 2020-01-02 06:33:52
问题 I'm using this code to remove the vcl styles from the non client area of a form. type TFormStyleHookNC= class(TMouseTrackControlStyleHook) protected procedure PaintBackground(Canvas: TCanvas); override; constructor Create(AControl: TWinControl); override; end; constructor TFormStyleHookNC.Create(AControl: TWinControl); begin inherited; OverrideEraseBkgnd := True; end; procedure TFormStyleHookNC.PaintBackground(Canvas: TCanvas); var Details: TThemedElementDetails; R: TRect; begin if

execute exe in memory

给你一囗甜甜゛ 提交于 2020-01-02 06:30:12
问题 I was trying out this code. execute EXE from memory I am hitting on error "Types of actual and formal var parameters must be identical" . Any help in this regard is highly appreciated. ...... ReadProcessMemory(ProcInfo.hProcess, pointer(Context.Ebx + 8), @BaseAddress, 4, Bytes); <-- error is here ....... and ..... WriteProcessMemory(ProcInfo.hProcess, pointer(ImageNtHeaders.OptionalHeader.ImageBase), InjectMemory, InjectSize, Bytes); <---- error here ...... I am using Delphi XE2 and windows 7

How to change Edit control background color in FireMonkey?

半城伤御伤魂 提交于 2020-01-02 06:21:27
问题 I just can't find a way of changing background color of Edit control in my mobile FireMonkey application. 回答1: I dont know about FMX for mobile, but in FMX for Mac/Win you should do following steps: Right click on TEdit and select Edit Custom Style In Structure window, expand editstyle (TLayout) Put a TRectangle on content (TRectangle becomes child of content) Change Rectangle.HitTest to False Change Rectangle.Align to alClient Change Rectangle.Fill.Color to a custom color Change Rectangle

Delphi XML traversing

扶醉桌前 提交于 2020-01-02 06:13:09
问题 I am new to Delphi. I wanted to find all the authors under each subject. Here is my XML <?xml version="1.0"?> <catalog> <subject id="computer"> <book id="bk101"> <author>Gambardella, Matthew</author> <title>XML Developer's Guide</title> <genre>Computer</genre> <price>44.95</price> <publish_date>2000-10-01</publish_date> <description>An in-depth look at creating applications with XML.</description> </book> <book id="bk112"> <author>Galos, Mike</author> <title>Visual Studio 7: A Comprehensive