Recent

Author Topic: failed to create win32 control, error 87  (Read 11551 times)

Michael Collier

  • Sr. Member
  • ****
  • Posts: 329
failed to create win32 control, error 87
« on: March 01, 2016, 07:01:31 pm »
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][+][-]
  1. unit unit1;
  2.  
  3. {$mode objfpc}{$H+}
  4.  
  5. interface
  6.  
  7. uses
  8.   Classes, SysUtils, FileUtil, Forms, Controls, Graphics, Dialogs, ComCtrls,
  9.   ActnList, StdCtrls, ExtCtrls ;
  10.  
  11. type
  12.  
  13.   { Titem_frame }
  14.  
  15.   Titem_frame = class(TFrame)
  16.   private
  17.     { private declarations }
  18.   public
  19.     { public declarations }
  20.     procedure nest ( a_count : integer ) ;
  21.   end;
  22.  
  23.   { TForm1 }
  24.  
  25.   TForm1 = class(TForm)
  26.     procedure FormShow(Sender: TObject);
  27.   private
  28.     { private declarations }
  29.   public
  30.     { public declarations }
  31.   end;
  32.  
  33. var
  34.   Form1: TForm1;
  35.  
  36. implementation
  37.  
  38. {$R *.lfm}
  39.  
  40. { Titem_frame }
  41.  
  42. procedure Titem_frame.nest(a_count: integer);
  43. begin
  44.   // quit if we hafe done all frames
  45.   if (a_count = 0 ) then exit                    ;
  46.  
  47.   // create a nested frame
  48.   with Titem_frame.Create( self )  do begin
  49.     Name   := 'f'  + IntToStr(a_count)           ;
  50.     Dec(a_count)                                 ;
  51.     // set parant property - will crash here..
  52.     Parent := self                               ;
  53.     //
  54.     Align  := alClient                           ;
  55.     // recursive..
  56.     nest(a_count)                                ;
  57.   end;
  58. end;
  59.  
  60. { TForm1 }
  61.  
  62. procedure TForm1.FormShow(Sender: TObject);
  63. begin
  64.   with Titem_frame.Create ( self ) do begin
  65.     Name   :='frame1'                          ;
  66.     Parent := self                             ;
  67.     Align  := alClient                         ;
  68.     // Crashes at around 46 on my machine.
  69.     // In my real application which has more controls it seems to crash much lower..
  70.     nest(50)                                   ;
  71.   end;
  72. end;
  73.  
  74.  
  75. end.
  76.  
  77.  

It crashes into line 244 of Win32WSControls
Code: Pascal  [Select][+][-]
  1. raise Exception.Create('Failed to create win32 control, error: ' + IntToStr(AErrorCode) + ' : ' + GetLastErrorText(AErrorCode));
  2.  

Cyrax

  • Hero Member
  • *****
  • Posts: 836
Re: failed to create win32 control, error 87
« Reply #1 on: March 02, 2016, 07:47:27 am »
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

  • Hero Member
  • *****
  • Posts: 18764
  • To Europe: simply sell USA bonds: dollar collapses
Re: failed to create win32 control, error 87
« Reply #2 on: March 02, 2016, 08:46:21 am »
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
« Last Edit: March 02, 2016, 08:49:41 am by Thaddy »
If Europe sells their USA bonds the USD will collapse. Europe can affort that given average state debts. The USA can't affort that. Just an advice...

Thaddy

  • Hero Member
  • *****
  • Posts: 18764
  • To Europe: simply sell USA bonds: dollar collapses
Re: failed to create win32 control, error 87
« Reply #3 on: March 02, 2016, 08:56:52 am »
Time to upgrade to ReactOS  8-)
If Europe sells their USA bonds the USD will collapse. Europe can affort that given average state debts. The USA can't affort that. Just an advice...

Michael Collier

  • Sr. Member
  • ****
  • Posts: 329
Re: failed to create win32 control, error 87
« Reply #4 on: March 02, 2016, 09:38:59 am »
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][+][-]
  1. procedure TForm1.ToolButton1Click(Sender: TObject);
  2. var i : integer ;
  3. begin
  4.   for i := 0 to 1000 do begin
  5.     with Titem_frame.Create(self) do begin
  6.       name := 'f' + IntToStr(i);
  7.       parent  := self ;
  8.       Align:= alTop;
  9.     end;
  10.   end;
  11. end;  

balazsszekely

  • Guest
Re: failed to create win32 control, error 87
« Reply #5 on: March 02, 2016, 09:42:44 am »
@Michael Collier
With some xp related reference:
https://blogs.msdn.microsoft.com/oldnewthing/20031218-00/?p=41453

Thaddy

  • Hero Member
  • *****
  • Posts: 18764
  • To Europe: simply sell USA bonds: dollar collapses
Re: failed to create win32 control, error 87
« Reply #6 on: March 02, 2016, 09:48:55 am »
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.
If Europe sells their USA bonds the USD will collapse. Europe can affort that given average state debts. The USA can't affort that. Just an advice...

Cyrax

  • Hero Member
  • *****
  • Posts: 836
Re: failed to create win32 control, error 87
« Reply #7 on: March 02, 2016, 09:53:04 am »
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.

Wrong. Frames and other controls can be created at run time, too.

balazsszekely

  • Guest
Re: failed to create win32 control, error 87
« Reply #8 on: March 02, 2016, 10:00:24 am »
@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).
« Last Edit: March 02, 2016, 10:08:12 am by GetMem »

Thaddy

  • Hero Member
  • *****
  • Posts: 18764
  • To Europe: simply sell USA bonds: dollar collapses
Re: failed to create win32 control, error 87
« Reply #9 on: March 02, 2016, 10:30:26 am »
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.

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 ;)
« Last Edit: March 02, 2016, 10:34:57 am by Thaddy »
If Europe sells their USA bonds the USD will collapse. Europe can affort that given average state debts. The USA can't affort that. Just an advice...

Thaddy

  • Hero Member
  • *****
  • Posts: 18764
  • To Europe: simply sell USA bonds: dollar collapses
Re: failed to create win32 control, error 87
« Reply #10 on: March 02, 2016, 10:40:15 am »
@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 >:D.
« Last Edit: March 02, 2016, 10:42:57 am by Thaddy »
If Europe sells their USA bonds the USD will collapse. Europe can affort that given average state debts. The USA can't affort that. Just an advice...

balazsszekely

  • Guest
Re: failed to create win32 control, error 87
« Reply #11 on: March 02, 2016, 10:44:05 am »
@Thaddy
It was always possible to create frames at runtime(both delphi and lazarus).

Thaddy

  • Hero Member
  • *****
  • Posts: 18764
  • To Europe: simply sell USA bonds: dollar collapses
Re: failed to create win32 control, error 87
« Reply #12 on: March 02, 2016, 10:46:25 am »
@Thaddy
It was always possible to create frames at runtime(both delphi and lazarus).
I know, I checked, it's a bug.... >:D

Oh, well, so may patents not implemented correctly including mine(just 1)  ;) KOL  uses the design time only paradigm to the full.
« Last Edit: March 02, 2016, 10:52:39 am by Thaddy »
If Europe sells their USA bonds the USD will collapse. Europe can affort that given average state debts. The USA can't affort that. Just an advice...

Michael Collier

  • Sr. Member
  • ****
  • Posts: 329
Re: failed to create win32 control, error 87
« Reply #13 on: March 02, 2016, 11:18:45 am »
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

  • Guest
Re: failed to create win32 control, error 87
« Reply #14 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.

 

TinyPortal © 2005-2018