Error Creating Window Device Context Delphi
Free SFTP, SCP and FTP client for Windows News Introduction SSH Client SFTP Client FTP Client Download Install Donate Documentation Guides F.A.Q. Scripting .NET & COM Library Screenshots Translations Support Forum Tracker History Topic "Error creating window device context" [Reply to topic] [Log in] [Forum Index] [Forum "Automatic Bug Reports"] [Previous topic] [Next topic] Author Message jason.peters@... Guest Posted: 2014-10-20 17:14 Error creating window device context [Reply with quote]
here for a quick overview of the site Help Center Detailed answers to any questions you might have Meta Discuss the workings and policies of this site About Us Learn more about Stack Overflow the company Business Learn more about hiring developers or posting ads with us Stack Overflow Questions Jobs Documentation Tags Users Badges Ask Question x Dismiss Join the Stack Overflow Community Stack Overflow is a community of 4.7 million programmers, just like you, helping https://winscp.net/forum/viewtopic.php?t=14448 each other. Join them; it only takes a minute: Sign up Delphi/GDI+: When is a Device Context created/destroyed? up vote 2 down vote favorite 2 Normally using GDI+ in Delphi you can use a TPaintBox, and paint during the OnPaint event: procedure TForm1.PaintBox1Paint(Sender: TObject); var g: TGPGraphics; begin g := TGPGraphics.Create(PaintBox1.Canvas.Handle); try g.DrawImage(FSomeImage, 0, 0); finally g.Free; http://stackoverflow.com/questions/1615984/delphi-gdi-when-is-a-device-context-created-destroyed end; end; The problem with this paradigm is that creating a destroying a Graphics object each time is wasteful and poorly performing. Additionally, there are a few constructs availabe in GDI+ you can only use when you have a persistent Graphics object. The problem, of course, is when can i create that Graphics object? i need to know when the handle becomes available, and then when it is no longer valid. i need this information so i can create and destroy my Graphics object. Solution Attempt Nº1 i can solve the creation problem by creating it when it is really needed - on the first time the paint cycle is called: procedure TForm1.PaintBox1Paint(Sender: TObject); begin if FGraphics = nil then FGraphics := TGPGraphics.Create(PaintBox1.Canvas.Handle); FGraphics.DrawImage(FSomeImage, 0, 0); end; But i have to know when the device context is no longer valid, so i can destroy my FGraphcis object, so that it is re-created the next time it's needed. If for some reason the TPaintBox's device context gets recreated, i would be drawing
thrID : DWORD; begin thr := CreateThread(nil, 0, @mConnectToServerFunc, nil, 0, thrID); end; My nTier application uses mConnectToServer to connect http://www.delphigroups.info/2/52/413469.html to an Asta Server linked to a Firbird Database. mConnectToServer populates about 20 ClientDataSets and sets up the main form. All appears to be swell, application starts, datasets populates and the rises in the east until I do something. Something as in anything Anything including closing the application gives me this {*word*193} little tome: EOutOfResources with message 'Error creating error creating window device context What have I done to deserve such treatment? What should I to prevent this? Thanks and enjoy your day, John Ullom Liz Delphi Developer Thu, 08 Oct 2009 17:46:14 GMT Re:Thread causes error QuoteJohn Ullom wrote: > thr := CreateThread(nil, 0, @mConnectToServerFunc, nil, 0, thrID); > EOutOfResources with message 'Error creating window device context > error creating window What have I done to deserve such treatment? What should I to > prevent this? looks ok on face value.. only thing I would say is that thr and thrID should be cardinals maybe, does that make it work? Id doubt it, but maybe... Ive always used the TThread way of working with threads mind, although the quick test I just did with CreateThread worked.. :) -- Liz the Brit Delphi things I have released: http://www.xcalibur.co.uk/DelphiThings Rob Kenned Delphi Developer Fri, 09 Oct 2009 13:44:50 GMT Re:Thread causes error QuoteJohn Ullom wrote: > I have a thread. I create it thus: > procedure TfrmMain.mCreateConnectThread; > var > thr : THandle; > thrID : DWORD; > begin > thr := CreateThread(nil, 0, @mConnectToServerFunc, nil, 0, thrID); Does your thread do any memory operations at all? This includes no just calls to GetMem or TObject.Create, but also string and dynamic-array allocations. You need to set the IsMultithread global variable to True when you create a thread using just the API. If you create threads with T