Recent

Author Topic: Code completion in Objective Pascal  (Read 3237 times)

zbyna

  • New Member
  • *
  • Posts: 46
Code completion in Objective Pascal
« on: June 19, 2015, 03:08:24 pm »
Hi all,
I am trying my first Cocoa steps:
(this program is slightly modification the one from lazarus wiki)
Code: [Select]
program project1;

{$mode objfpc}{$H+}
{$modeswitch objectivec2}

uses
CocoaAll;

type
  { TMyDelegate }
  TMyDelegate = objcclass(NSObject)
  public
    procedure HandleButtonClick(sender: id); message 'HandleButtonClick:';
  end;

var
  appName: NSString;
  window: NSWindow;
  pool: NSAutoreleasePool;
  lText: NSTextField;
  lButton: NSButton;
  lDelegate: TMyDelegate;

procedure TMyDelegate.HandleButtonClick(sender: id);
begin
  lText.setStringValue(NSSTR('New text!'));
end;

begin
  // Autorelease pool, app and window creation
  pool := NSAutoreleasePool.new;
  NSApp := NSApplication.sharedApplication;
  NSApp.setActivationPolicy(NSApplicationActivationPolicyRegular);
  appName := NSProcessInfo.processInfo.processName;
  window := NSWindow.alloc.initWithContentRect_styleMask_backing_defer(NSMakeRect(0, 0, 200, 200),
    NSTitledWindowMask or NSClosableWindowMask or NSMiniaturizableWindowMask or NSResizableWindowMask,
    NSBackingStoreBuffered, False).autorelease;

  // text label
  lText := NSTextField.alloc.initWithFrame(NSMakeRect(50, 50, 120, 50)).autorelease;
  lText.setBezeled(False);
  lText.setDrawsBackground(False);
  lText.setEditable(False);
  lText.setSelectable(False);
  lText.setStringValue(NSSTR('NSTextField'));
  window.contentView.addSubview(lText);

  // button
  lButton := NSButton.alloc.initWithFrame(NSMakeRect(50, 100, 120, 50)).autorelease;
  window.contentView.addSubview(lButton);
  lButton.setTitle(NSSTR('Button title!'));
  lButton.setButtonType(NSMomentaryLightButton);
  lButton.setBezelStyle(NSRoundedBezelStyle);

  // button event handler setting
  lDelegate := TMyDelegate.alloc.init;
  lButton.setTarget(lDelegate);
  lButton.setAction(ObjCSelector(lDelegate.HandleButtonClick));

  // Window showing and app running
  window.center;
  window.setTitle(appName);
  window.makeKeyAndOrderFront(nil);
  NSApp.activateIgnoringOtherApps(true);
  NSApp.run;
end. 

When I try code completion (CTRL+space) for example on:
Code: [Select]
window. I would expect in ideal world  ;)  list of all NSWindow methods.
Unfornutely reality is:
Code: [Select]
NSWindowScripting.inc(40,76) Error: cycle detected
line 40 from NSWindowScripting.inc:
Code: [Select]
NSScripting_NSWindowCategory = objccategory external name 'NSScripting' (NSWindow)
Is this a bug or  some sort of behaviour which is based on differencies between ObjC and FPC model abstraction ? I am not able to judge  :-\  :( And of course the problem may be between the table and keyboard :)
Thanks for clarifying.
   zbyna
« Last Edit: June 19, 2015, 03:37:03 pm by zbyna »

Jonas Maebe

  • Hero Member
  • *****
  • Posts: 674
Re: Code completion in Objective Pascal
« Reply #1 on: June 23, 2015, 07:50:22 pm »
It's probably best to file a bug report at http://bugs.freepascal.org/set_project.php?project_id=1

zbyna

  • New Member
  • *
  • Posts: 46
Re: Code completion in Objective Pascal
« Reply #2 on: June 23, 2015, 09:53:40 pm »
Thanks for reply.
Reported.