Delphi

How to load a png image into a TImage

被刻印的时光 ゝ 提交于 2020-07-03 02:36:12
问题 I am trying to load a png image into a TImage with Delphi XE4. The png starts off in a stream: E.g. Stream := TMemoryStream.Create; try Stream.LoadFromFile('c:\file.png'); Stream.Position := 0; Image1.Picture.Graphic.LoadFromStream(Stream); finally Stream.Free; end; I get an AV when I run this code. Can anyone tell me what I'm doing wrong? Thanks. 回答1: The TImage.Picture.Graphic property is nil until you load a graphic into the Picture . What you are asking for can be achieved as follows:

Can task-switching keyboard shortcuts be disabled in W7 using Delphi?

杀马特。学长 韩版系。学妹 提交于 2020-07-02 18:07:27
问题 MY application has had a mode for years where the customer can 'disable access to the OS'. Obviously this feature goes against the grain (at least as far as Windows is concerned) but there are installations where my App is the only program that should ever be visibile to a machine operator amd in this case such a feature is useful. The technigue I used was built from several 'layers': Hide the taskbar and button. Disable task-switching. Disable my main form system icons. To disable the

Why FreeAndNil implementation doing Nil before Free?

痞子三分冷 提交于 2020-06-29 06:41:46
问题 If you will look at the code of FreeAndNil procedure you will see: procedure FreeAndNil(var Obj); var Temp: TObject; begin Temp := TObject(Obj); Pointer(Obj) := nil; Temp.Free; end; What is the reason they assigning Nil to an object reference and only after this destroying it? Why not vice-versa? 回答1: I can think of two reasons for doing it this way round, neither of which seems at all compelling. Reason 1: to guarantee that the reference is set to nil in case an exception is raised The

How wait for TWebBrowser is loaded in FOR … TO … DO?

…衆ロ難τιáo~ 提交于 2020-06-28 11:08:54
问题 I have a this code: for i:=0 to Memo1.Lines.Count-1 do begin while WebBrowser1.Busy do Application.ProcessMessages; WebBrowser1.OleObject.Document.Links.item(cat[i]).click; subcatList; end; but WebBrowser1 run several times in spite of the expectations of the procedure. How do I start WebBrowser1 not in the background or what is the solution? 回答1: You need to implement 3 events of TWebBrowser, BeforeNavigate2, DocumentComplete and NavigateComplete2 TForm1 = class(TForm) private CurDispatch:

How to use API Winspool.EnumprinterData in Delphi?

女生的网名这么多〃 提交于 2020-06-28 05:01:46
问题 Does anyone have experience with using the Winspool.EnumprinterData API in Delphi? I found a demo for C++: https://s-kita.hatenablog.com/entry/20120227/1330353801 I tried to covert it to Delphi as below: procedure TForm1.GetPrinterData; var hPrinter : THandle; pInfo: PPrinterInfo2; bytesNeeded: DWORD; dwRet : DWORD; dwIndex: DWORD; pValueName: PWideChar; pTagName: PWideChar; cbValueName: DWORD; pcbValueName : DWORD; pType: DWORD; pData: PByte; cbData: DWORD; pcbData: PDWORD; i : Integer;

Sporadic Access Violation after porting from D2006 to XE5, doesn't happen in XP compatibility mode

青春壹個敷衍的年華 提交于 2020-06-27 18:03:57
问题 We have a large application that works fine in Delphi 2006. We've moved it to XE5 and are experiencing frequent sporadic Access Violations. We're using VCL forms and a number of DevExpress and other third party components. We're working in Windows 7 Professional with Delphi XE Enterprise, Version 19.0.14356.6604. We've looked on line, here and elsewhere, for postings about A/Vs after porting to XE5 but haven't found anything that seems relevant to our problem. Here's what we know about the A

Why FreeAndNil implementation doing Nil before Free?

笑着哭i 提交于 2020-06-27 07:00:15
问题 If you will look at the code of FreeAndNil procedure you will see: procedure FreeAndNil(var Obj); var Temp: TObject; begin Temp := TObject(Obj); Pointer(Obj) := nil; Temp.Free; end; What is the reason they assigning Nil to an object reference and only after this destroying it? Why not vice-versa? 回答1: I can think of two reasons for doing it this way round, neither of which seems at all compelling. Reason 1: to guarantee that the reference is set to nil in case an exception is raised The

Why code in any unit finalization section of a package is not executed at shut down?

徘徊边缘 提交于 2020-06-25 18:46:25
问题 I have an application that uses statically-linked runtime packages as well as designtime packages that use them. For some reason the code in any unit finalization section is not being run at runtime (I can't tell when this started happening). finalization ShowMessage('Goodbye'); end. Shutting Delphi down shows the message, but not when my application shuts down. It gets weirder in that if I put a breakpoint on ShowMessage, it breaks there but does not execute the line. If there are multiple

Parallel processing strings Delphi full available CPU usage

不打扰是莪最后的温柔 提交于 2020-06-25 08:58:33
问题 The goal is to achieve full usage of the available cores, in converting floats to strings in a single Delphi application. I think this problem applies to the general processing of string. Yet in my example I am specifically using the FloatToStr method. What I am doing (I've kept this very simple so there is little ambiguity around the implementation): Using Delphi XE6 Create thread objects which inherit from TThread, and start them. In the thread execute procedure it will convert a large

Load image from embedded resource

流过昼夜 提交于 2020-06-25 08:37:43
问题 I am trying to assign an image(Image1) a picture at Run-time. Since I can't set a property to load from resource. So I need to load at run time. I have the code procedure TForm1.FormCreate(Sender: TObject); var RS:Tresourcestream ; begin RS := TResourceStream.Create(HInstance,'Splashscreen_Background', RT_RCDATA); image1.Picture.Bitmap.LoadFromResourcename(HInstance,'splashscreen_background'); end; But it just loads the forms with a blank Image. aswell as: procedure TForm1.FormCreate(Sender: