Icon View Thread

The following is the text of the current message along with any replies.
Messages 1 to 6 of 6 total
Thread Subclass for form
Sun, Nov 1 2015 5:28 PMPermanent Link

Christian Kaufmann

I try this:

 // For this class I have a .wbf file
 TFViewEntryIndividual = class(TForm)
 protected
   procedure Init; virtual; abstract;
 end;


 // then I define two sub classes
 TFViewEntryIndividualByAthlete = class(TFViewEntryIndividual)
 protected
   procedure Init; override;
 end;

 TFViewEntryIndividualByEvent = class(TFViewEntryIndividual)
 protected
   procedure Init; override;
 end;


The reason for this is, I just register view classes (class of TForm) and depending on the menu
click, the objects are created on the fly.

The code above fails because the usage of ClassName in TFormControl.LoadFromResource.

Unfortunately I didn't find a solution where I can work with "reference to function". I just can
create a list of classes and then my generic code for the menu item click looks like this:


procedure TFMain.SideMenuClick(Sender: TObject);
var                
 l : TBSMenuLabel;
begin
 l := TBSMenuLabel(Sender);
 l.Selected := True;
 if Assigned(FView)
   then FView.Free;
 FView := FViews[l.Tag].Create(Self);
end;


FViews is an array of "class of TFormControl". Any suggestions on how this could be solved?
`
cu Christian
Mon, Nov 2 2015 2:13 PMPermanent Link

Tim Young [Elevate Software]

Elevate Software, Inc.

Avatar

Email timyoung@elevatesoft.com

Christian,

<< The code above fails because the usage of ClassName in TFormControl.LoadFromResource. >>

Yes, there's really no way around this - the class name dictates which form resource to load.

<< Unfortunately I didn't find a solution where I can work with "reference to function". >>

In EWB, you can use references to functions/procedures in the same way as you can method references:

http://www.elevatesoft.com/manual?action=viewtopic&id=ewb2&topic=Type_Declarations

(the last example)

EWB uses an array of function references for the animation easing calculations.

Tim Young
Elevate Software
www.elevatesoft.com
Mon, Nov 2 2015 2:48 PMPermanent Link

Christian Kaufmann

Tim Young [Elevate Software] wrote:

> In EWB, you can use references to functions/procedures in the same way as you can method
> references:
>
> http://www.elevatesoft.com/manual?action=viewtopic&id=ewb2&topic=Type_Declarations
>
> (the last example)

Sounds good. But it seems, it doesn't work with class methods. I tried this:

 TBSViewPanel = class(TFormControl)
 public
   class function GenerateView(AOwner: TComponent): TBSViewPanel; virtual;
 end;

 TBSViewGenerateFunc = function(AOwner: TComponent): TBSViewPanel;

 TMyView = class(TBSViewPanel)
  ...
 end;

Now TMyView.GenerateView is not accepted as parameter of type TBSViewGenerateFunc.

[Error] main.wbs (148,3): There is no function or procedure declaration that matches the
RegisterMenu(MEntry, TFViewEntryMeet.GenerateView()) reference


Does it have to be a global method?


cu Christian
Mon, Nov 2 2015 3:10 PMPermanent Link

Tim Young [Elevate Software]

Elevate Software, Inc.

Avatar

Email timyoung@elevatesoft.com

Christian,

<< Now TMyView.GenerateView is not accepted as parameter of type TBSViewGenerateFunc.  >>

Please post all of the code relevant to what you're trying to do, especially the actual RegisterMenu call.

Tim Young
Elevate Software
www.elevatesoft.com
Mon, Nov 2 2015 3:12 PMPermanent Link

Tim Young [Elevate Software]

Elevate Software, Inc.

Avatar

Email timyoung@elevatesoft.com

Christian,

Actually, never mind - I spotted the issue.  You forgot the "of object" part for your method type declaration:

 TBSViewGenerateFunc = function(AOwner: TComponent): TBSViewPanel of object; <<<<<<<<<

Tim Young
Elevate Software
www.elevatesoft.com
Mon, Nov 2 2015 4:04 PMPermanent Link

Christian Kaufmann

Tim Young [Elevate Software] wrote:
>
>   TBSViewGenerateFunc = function(AOwner: TComponent): TBSViewPanel of object; <<<<<<<<<
>
Thanks.

cu Christian
Image