failed to create win32 control, error 87 lazarus / 31-LCL ---------------------------------------------------------------------- Michael Collier · 2016-03-01 18:01 I get this error in my application when I reach a certain level of nested frames on windows NT. failed to create win32 control, error 87 Here is an example that crashes, just paste the code into a new form and run.. Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i unit unit1; {$mode objfpc}{$H+} interface uses  Classes, SysUtils, FileUtil, Forms, Controls, Graphics, Dialogs, ComCtrls,  ActnList, StdCtrls, ExtCtrls ; type   { Titem_frame }   Titem_frame = class(TFrame)  private    { private declarations }  public    { public declarations }    procedure nest ( a_count : integer ) ;  end;   { TForm1 }   TForm1 = class(TForm)    procedure FormShow(Sender: TObject);  private    { private declarations }  public    { public declarations }  end; var  Form1: TForm1; implementation {$R *.lfm} { Titem_frame } procedure Titem_frame.nest(a_count: integer);begin  // quit if we hafe done all frames  if (a_count = 0 ) then exit                  ;   // create a nested frame  with Titem_frame.Create( self )  do begin    Name   := 'f'  + IntToStr(a_count)           ;    Dec(a_count)                                 ;    // set parant property - will crash here..    Parent := self                             ;    //    Align  := alClient                           ;    // recursive..    nest(a_count)                                ;  end;end; { TForm1 } procedure TForm1.FormShow(Sender: TObject);begin  with Titem_frame.Create ( self ) do begin    Name   :='frame1'                        ;    Parent := self                             ;    Align  := alClient                         ;    // Crashes at around 46 on my machine.    // In my real application which has more controls it seems to crash much lower..    nest(50)                                 ;  end;end;  end.   It crashes into line 244 of Win32WSControls Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i raise Exception.Create('Failed to create win32 control, error: ' + IntToStr(AErrorCode) + ' : ' + GetLastErrorText(AErrorCode)); ---------------------------------------------------------------------- Cyrax · 2016-03-02 06:47 You are running out of USER and/or GDI handles. That's why you are getting that error. Are you really developing under old NT series? Not Windows 2000, XP, Vista+? ---------------------------------------------------------------------- Thaddy · 2016-03-02 07:46 That makes sense, from win2000 onwards it is very unlikely that you see that error.... Btw: FPC doesn't support NT4 or worse. Way back: You receive a "System error 87 has occurred. RESOLUTION To resolve this problem, obtain the latest service pack for Windows NT 4.0 or the individual software update. For information on obtaining the latest service pack, please go to:     152734 How to obtain the latest Windows NT 4.0 service pack For information on obtaining the individual software update, contact Microsoft Product Support Services. For a complete list of Microsoft Product Support Services phone numbers and information on support costs, please go to the following address on the World Wide Web: http://support.microsoft.com/default.aspx?scid=fh;EN-US;CNTACTMS ---------------------------------------------------------------------- Thaddy · 2016-03-02 07:56 Time to upgrade to ReactOS ---------------------------------------------------------------------- Michael Collier · 2016-03-02 08:38 Oops, I meant windows XP (service pack 3), the same error occurs on windows vista (service pack 2). I keep projects on ubuntu server and compile from a range of machines over a samba. Sorry for the confusion, my bad. Are you certain it is resource related, I can create 200 times as many frames if I don't nest them. Here is similar code creating twice as many frames but using the main form as parent. Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i procedure TForm1.ToolButton1Click(Sender: TObject);var i : integer ;begin  for i := 0 to 1000 do begin    with Titem_frame.Create(self) do begin      name := 'f' + IntToStr(i);      parent  := self ;      Align:= alTop;    end;  end;end; ---------------------------------------------------------------------- balazsszekely · 2016-03-02 08:42 @Michael Collier With some xp related reference: https://blogs.msdn.microsoft.com/oldnewthing/20031218-00/?p=41453 ---------------------------------------------------------------------- Thaddy · 2016-03-02 08:48 Frames should never cause that because they are design time only. Do you have some little project that replicates the issue, because I can't replicate it. ---------------------------------------------------------------------- Cyrax · 2016-03-02 08:53 Quote from: Thaddy on March 02, 2016, 09:48:55 amFrames should never cause that because they are design time only. Do you have some little project that replicates the issue, because I can't replicate it. Wrong. Frames and other controls can be created at run time, too. ---------------------------------------------------------------------- balazsszekely · 2016-03-02 09:00 @Thaddy Checked with Window Detective(see screenshot). From the operating system's perspective, the frame is considered a window, so nesting a frame into a form, is still nesting a window in window. Multiple nesting will eventually lead to the nesting limit exception(see the link in my previous post). ---------------------------------------------------------------------- Thaddy · 2016-03-02 09:30 Quote from: Cyrax on March 02, 2016, 09:53:04 amQuote from: Thaddy on March 02, 2016, 09:48:55 amFrames should never cause that because they are design time only. Do you have some little project that replicates the issue, because I can't replicate it. Wrong. Frames and other controls can be created at run time, too. According to the patent! from Allen Bauer et. al. they shouldn't That's a design flaw in Lazarus if it is really accepted to create frames at run-time. By design  it is a design-time container and not something that could be used at run-time. Dead give-away: the patent is about not taking up any resources. [edit] So you mean to tell me that only KOL implements it correctly ---------------------------------------------------------------------- Thaddy · 2016-03-02 09:40 @Michael Collier: Who is self? You mean form.self or control.self? Don't use with, plz. I can crash anything with with. You need some self esteem to write code like that . ---------------------------------------------------------------------- balazsszekely · 2016-03-02 09:44 @Thaddy It was always possible to create frames at runtime(both delphi and lazarus). ---------------------------------------------------------------------- Thaddy · 2016-03-02 09:46 Quote from: GetMem on March 02, 2016, 10:44:05 am@Thaddy It was always possible to create frames at runtime(both delphi and lazarus). I know, I checked, it's a bug.... Oh, well, so may patents not implemented correctly including mine(just 1)  KOL  uses the design time only paradigm to the full. ---------------------------------------------------------------------- Michael Collier · 2016-03-02 10:18 Sorry about use of create/with, my real application doesn't use that method, just tried to keep snippet small for posting but probably made things worse..will try to provide better example after a bit more investigation into this, thanks for help ---------------------------------------------------------------------- balazsszekely · 2016-03-02 10:20 @Thaddy I really don't want to insist on this issue, but in my opinion creating frames at runtime is a perfectly valid thing, although I do agree, the main advantage of the frame is that you can create multiple instances of it at design time. ---------------------------------------------------------------------- Thaddy · 2016-03-02 15:13 Quote from: GetMem on March 02, 2016, 11:20:19 am@Thaddy I really don't want to insist on this issue, but in my opinion creating frames at runtime is a perfectly valid thing, although I do agree, the main advantage of the frame is that you can create multiple instances of it at design time. All brilliant idea's have side effects... In my opinion this can change at any given moment.... Don't use frames at runtime. Simple. Ok, you can... but then at least don't moan when somebody implements it correctly. Which you would probably do because it breaks your code The Hives: I hate to say I told You So. But I only insist on something obvious Oh, we can't. that would be a patent infrinchment .... https://www.youtube.com/watch?v=Uz1Jwyxd4tE ---------------------------------------------------------------------- Martok · 2016-03-02 15:30 Out of curiosity, do you have a link on why frames should be designtime only? I've always thought their entire point was that they can be created at runtime, with designtime placement being a "bonus". Never heard of a patent either (and why can you get a patent for what is essentially "stream this panel's components from a different resource" anyway?) ---------------------------------------------------------------------- Thaddy · 2016-03-02 15:34 Quote from: Martok on March 02, 2016, 04:30:28 pmOut of curiosity, do you have a link on why frames should be designtime only? I've always thought their entire point was that they can be created at runtime, with designtime placement being a "bonus". Never heard of a patent either (and why can you get a patent for what is essentially "stream this panel's components from a different resource" anyway?) Development of multiple classes of user interfaces for a software application United States Methods and systems for developing multiple classes of user interfaces for a software application are disclosed. A master view of a software application is displayed, at a computer system, for use in developing multiple classes of user interfaces for the software application wherein each of the multiple classes pertain to at least one form factor for a device to execute the software application. Subordinate views are created, at the computer system, wherein each of the subordinate views pertain to one of the multiple classes of user interfaces and comprise deltas that alter the master view such that a first subordinate view is displayed based on the master view combined with a first group of the deltas for the first subordinate view. A change is propagated to the master view to each of the subordinate views, at the computer system. Inventors:         Allen Bauer For the under educated: that's a frame! ---------------------------------------------------------------------- Martok · 2016-03-02 15:55 (That's US20150143337 in case anyone wants to look it up) This patent is from 2013 (granted 2015), about different UIs for different platforms with some common foundations. Basically, something like CSS @media selectors only for forms. Probably refers to Firemonkey/FMX, although I'd expect WPF to have had something similar. I know Android has had this feature for a long time (you can have XML overlays for your app layout definitions depending on device DPI. Same goes for drawables). It's trivial if you have XUL, so Mozilla probably has something like this as well. Heck, Powerpoint master slides are the same concept. For the younger: Frames were a D5 innovation, released in 1998. ---------------------------------------------------------------------- Michael Collier · 2016-03-03 15:24 Thanks, it seems the 50 nested handles limit was causing my problem. It seemed strange at first because I'm not nesting 50 frames (I'm doing about 13), but I am placing the frames inside other win controls which I guess pushed the count up.