Objective Pascal TForm delegate 'windowWillResize:toSize:' lazarus / 33-macOS - Mac OS X ---------------------------------------------------------------------- Shebuka · 2021-02-11 16:53 Hello, I've spent a good part of the day trying to figure out how to implement an NSWindow 'windowWillResize:toSize:' delegate in an existing TForm class. After many trials and errors and wiki posts, this is what I came out with: 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 PreviewWin; {$mode objfpc}{$H+}{$LongStrings On} {$modeswitch objectivec1}{$modeswitch objectivec2} interface uses  Classes, SysUtils, LazFileUtils, LResources, LMessages, Forms, Controls, Graphics,  Dialogs, ComCtrls, ExtCtrls, StdCtrls,  CocoaWindows, MacOSAll, CocoaAll;  type  { TPreviewWindowDelegate }   TPreviewWindowDelegate = objcclass(NSObject, NSWindowDelegateProtocol)  public    function windowWillResize_toSize(sender: NSWindow; frameSize: NSSize): NSSize; message 'windowWillResize:toSize:';  end;   { TFrm_Preview }   TFrm_Preview = class(TForm)   private    { private declarations }       FPreserveAspect: Bool;    FAspectRatio: Double;     previewWindowDelegate: TPreviewWindowDelegate;    end;  var  Frm_Preview: TFrm_Preview;  implementation {$R *.lfm}   { TPreviewWindowDelegate } function TPreviewWindowDelegate.windowWillResize_toSize(sender: NSWindow; frameSize: NSSize): NSSize;begin  result := frameSize;   if Frm_Preview.FPreserveAspect then  begin    // forse result to match forced aspectRatio size    result.height := result.width / Frm_Preview.FAspectRatio  end;end;  { TFrm_Preview } procedure TFrm_Preview.FormCreate(Sender: TObject);var                                     win: NSWindow;begin  previewWindowDelegate := TPreviewWindowDelegate.alloc.init();   //NSWindow(Self.Handle).setDelegate(previewWindowDelegate);   // is this enough instead of the following code?   win := TCocoaWindowContent(Self.Handle).lclOwnWindow;  if Assigned(win) then  begin    win.setDelegate(previewWindowDelegate);  end;   FPreserveAspect := True;  FAspectRatio := 4 / 3;   end; procedure TFrm_Preview.FormDestroy(Sender: TObject);begin  previewWindowDelegate.release;end; ... but it still not building and spits some generic unknown error and I don't know what else to try... previewwin.pas(46,1) Error: Internal error 200609171 Can you please help me understand what's wrong and how to do it correctly? edit: Lazarus 2.1.0 r64158M FPC 3.2.0 x86_64-darwin-cocoa ---------------------------------------------------------------------- skalogryz · 2021-02-11 19:07 try to disable debug info and recompile the project ---------------------------------------------------------------------- Seenkao · 2021-02-11 20:40 Quote from: skalogryz on February 11, 2021, 08:07:36 pmtry to disable debug info and recompile the project Может эту проблему уже начнут решать? С каких пор, считается, что если включена отладка, то код с включенной отладкой может выдавать ошибки? Eng: Maybe this problem will already be solved? Since when is it believed that if debugging is enabled, then code with debugging enabled can generate errors? ---------------------------------------------------------------------- Jonas Maebe · 2021-02-11 22:30 The internal error comes from using DWARFv3 (-gw3). There's indeed a bug in the compiler related to generating debug information for Objective-Pascal with that format. Switching to DWARFv2 (-gw) will fix that. ---------------------------------------------------------------------- Shebuka · 2021-02-12 11:54 Quote from: Jonas Maebe on February 11, 2021, 11:30:52 pmThe internal error comes from using DWARFv3 (-gw3). There's indeed a bug in the compiler related to generating debug information for Objective-Pascal with that format. Switching to DWARFv3 (-gw) will fix that. Setting 'Type of debug info' to 'Dwarf with sets (-gw -godwarfsets)' solved the build problem and now the app builds and the form is resizing with given aspect ratio. But I also have several errors: Compile Project, Mode: Debug, Target: XXXXXX: Success, Errors: 8 Error: :181956:10: warning: section "__datacoal_nt" is deprecated Error: .section __DATA, __datacoal_nt, coalesced Error: :181956:10: note: change section name to "__data" Error: .section __DATA, __datacoal_nt, coalesced Error: :182146:10: warning: section "__datacoal_nt" is deprecated Error: .section __DATA, __datacoal_nt, coalesced Error: :182146:10: note: change section name to "__data" Error: .section __DATA, __datacoal_nt, coalesced Do I simply ignore them? ---------------------------------------------------------------------- Shebuka · 2021-02-12 11:59 I also don't fully understand from different snippets if the Handle is the actual NSWindow or if I need to get the lclOwnWindow out of handle? 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   NSWindow(Self.Handle).setDelegate(previewWindowDelegate); VS 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   win := TCocoaWindowContent(Self.Handle).lclOwnWindow;  if Assigned(win) then  begin    win.setDelegate(previewWindowDelegate);  end; What's (more) correct? ---------------------------------------------------------------------- Jonas Maebe · 2021-02-13 08:08 Quote from: Shebuka on February 12, 2021, 12:54:54 pmBut I also have several errors: Compile Project, Mode: Debug, Target: XXXXXX: Success, Errors: 8 Error: :181956:10: warning: section "__datacoal_nt" is deprecated Error: .section __DATA, __datacoal_nt, coalesced Error: :181956:10: note: change section name to "__data" Error: .section __DATA, __datacoal_nt, coalesced Error: :182146:10: warning: section "__datacoal_nt" is deprecated Error: .section __DATA, __datacoal_nt, coalesced Error: :182146:10: note: change section name to "__data" Error: .section __DATA, __datacoal_nt, coalesced Do I simply ignore them? Yes. These are actually (harmless) warnings from the assembler, but for some reason Lazarus shows them as errors.