Recent

Author Topic: Nested Events property ?  (Read 4474 times)

siegfriedn

  • New Member
  • *
  • Posts: 22
Nested Events property ?
« on: August 19, 2010, 02:04:08 pm »
Hi,

I am working on a component framework for Lazarus, I want to 'group' certain events in the object inspector. I have tried a lot of things but I have not succeeded and need your help.

I get the "Method name '''' must be an identifier" error message. (This seems to be generated in the Edit method of the TMethodPropertyEditor class in the \Lazarus\ideintf\propedits.pp file.

I have created a simple example code (attached below) which can be used to replicate the problem. It contains all the classes in one unit for simplicity. You need to create a new package and add the code into a unit. Tick the unit contains a Register procedure. you need to add LCL
and IDEIntf as requirements for the new package. Install the package.

The message occurs when you try to create a new OnEventTest event.

The 'nested' property (TEventTestProperties) is derived from TPersistent and it looks like GetComponent(0) does %) %) %) %) >:( %) not find the 'root component' (TEventTestEdit) properly when a new method name should be created. The new Method name can be the root component name and the name of the method (event).

I tried to create a custom property editor, but all my 'experiments' failed. (To be honest I was not 100% sure of what I was doing..)

It is actually quite frustrating to try to 'debug' this. If anyone can provide a link on where to find information to debug the Lazarus IDE, I would be grateful too.

Thanks,

Siegfried

--Example code below..

unit TestClasses;

{$mode objfpc}{$H+}

interface

uses
  Classes, SysUtils, StdCtrls, PropEdits;

type
  TOnEventTest = procedure (Sender: TObject; Param2: Integer) of object;

  { TEventTestProperties }

  TEventTestProperties = class(TPersistent)
  private
    FOnEventTest: TOnEventTest;
  public
    procedure DoEventTest(Sender: TObject; Param2: Integer); virtual;
  published
    property OEventTest: TOnEventTest read FOnEventTest write FOnEventTest;
  end;

  { TEventTestEdit }

  TEventTestEdit = class(TEdit)
  private
    FEventProperties: TEventTestProperties;
  public
    constructor Create(AOwner: TComponent); override;
    destructor Destroy; override;
    procedure Click; override;
  published
    property EventProperties: TEventTestProperties read FEventProperties write FEventProperties;
  end;

procedure Register;

implementation

procedure Register;
begin
  RegisterComponents('EventTest', [TEventTestEdit]);

  RegisterPropertyEditor(TypeInfo(TNotifyEvent), TEventTestProperties, 'EventProperties', TMethodProperty); //Make it TNotifyEvent so that the events appear on the Events tab!
end;

{ TEventTestEdit }

constructor TEventTestEdit.Create(AOwner: TComponent);
begin
  FEventProperties := TEventTestProperties.Create;
  inherited Create(AOwner);
end;

destructor TEventTestEdit.Destroy;
begin
  FEventProperties.Free;
  inherited Destroy;
end;

procedure TEventTestEdit.Click;
begin
  inherited Click;
  FEventProperties.DoEventTest(Self, 5);
end;

{ TEventTestProperties }

procedure TEventTestProperties.DoEventTest(Sender: TObject; Param2: Integer);
begin
  if Assigned(FOnEventTest) then
    FOnEventTest(Sender, Param2);
end;

end.



 

TinyPortal © 2005-2018