Recent

Author Topic: Tframes and user published propeties question.  (Read 5002 times)

jamie

  • Hero Member
  • *****
  • Posts: 6091
Tframes and user published propeties question.
« on: March 10, 2018, 12:44:34 am »
I thought it would be a great idea to make a common sheet of controls I used in several places
in an app, there by making sure they all work the same so the user can learn quickly how to
manipulate the set of controls..

 Along those lines, when these controls within the Tframe make changes, I check for the assignment
of an OnChange Event I put in there and if assigned I call it..

 The idea is when I drop this frame on the form I want to use it on, I thought that maybe I would
see the published additional property I put in there, but I don't..

  I can set it in the form.oncreate but I wish this would work the usual way..
Code: Pascal  [Select][+][-]
  1.  TNEWSMOVE = class(TFrame)
  2.     ArLeft: TArrow;
  3.     Arright: TArrow;
  4.     ArUp: TArrow;
  5.     Ardown: TArrow;
  6.     Panel1: TPanel;
  7.     procedure ArLeftClick(Sender: TObject);
  8.   private
  9.     fOnChange :TNotifyEvent;
  10.   public
  11.     LocateRect :TRect;
  12.   published
  13.     Property OnChanged :TNotifyEvent Read fOnChange write FOnChange;
  14.   end;                                  

This is a sample of what I was talking about..

Is it possible to see the Published Property "OnChange" in the OI when I drop it on the form ?

 This would make using the Frames the cats meow !
The only true wisdom is knowing you know nothing

jamie

  • Hero Member
  • *****
  • Posts: 6091
Re: Tframes and user published propeties question.
« Reply #1 on: March 10, 2018, 02:14:54 am »
What we need is a non-visual event object that has a single OnAction that when dropped on a
TFrame form will provide the OI a published property that can be set in the OI and defined at
app load through the usual methods of TReader etc..

 So what I did for the time being is to drop a Tlabel on the Frame and set it to invisible, set the caption
that reminds me what it's there for,  so I can see it at design time.
 
 That allows me to set the OnClick event in the OI in the form from which I decide to use the
frame in and in the frame code I can simply test the assignment and call the event .
 

  All this does is saves me from needing to define these events at startup in my code.


 Is there any such registered component that can provide a single event dispatch that can be
set via the OI ?

 This way when making a frame I can simply drop one of these OI editable events on the frame form,
one for each event for that frame!

Any one have any clues other than what I did?

The only true wisdom is knowing you know nothing

jamie

  • Hero Member
  • *****
  • Posts: 6091
Re: Tframes and user published propeties question.
« Reply #2 on: March 10, 2018, 04:06:07 am »
Just ran into an issue with Tframes

If I put more than one frame on my form and assign an event to the panel that is inside of them
the OI assigns the panel.click event to the same event..

 In other words, I have 5 Frames of the same that contain a Tpanel in them.

 The OI assigns the Onclick event of all five to the same event..

 the OI is not prepending the Instant Name to it...

  so is this a bug or am I not understanding something here?

I can manually create the events and then scroll through the selection in the OI to set them and
they work. That is, I name the events to that of the Main instance name along with the inner object..

 Instant1Panel.Onclick, Instant2PanelOnclock etc.

 The OI is just creating a single PanelOnclick and pointing all of them to the same one.

 is this normal?
The only true wisdom is knowing you know nothing

ASerge

  • Hero Member
  • *****
  • Posts: 2223
Re: Tframes and user published propeties question.
« Reply #3 on: March 10, 2018, 01:01:33 pm »
What I've done:
1. Added a new TFrame to an empty project.
2. Added TActionList and create new TAction. For example "Change".
3. Added TLabel to have something.
4. Wrote the code:
Code: Pascal  [Select][+][-]
  1.   protected
  2.     procedure Loaded; override;
  3. ...
  4. procedure TFrame1.Loaded;
  5. begin
  6.   inherited;
  7.   if Assigned(Change.OnExecute) then
  8.     Label1.Caption := 'Assigned!';
  9. end;
5. In the main form, added two frames, and one of them assigned the Change.OnExecute event.

Only this frame show label "Assigned!".

jamie

  • Hero Member
  • *****
  • Posts: 6091
Re: Tframes and user published propeties question.
« Reply #4 on: March 10, 2018, 03:05:45 pm »
Thanks, that's more on the lines of what I am doing using the Tlabel for the event object.

 Maybe I should write a TframeVent  class and register it so the OI can do this...

---
 On the issue of the OI generating method names for the events within the frame instances, I find
a large problem, one that for the time can only be correct via manual editing..

 from the form that host a frame I can set and set events of controls within the Frame instance and
the method event is planted in the Host form, however, the OI is not prepending the instant name
of the frame with the event name..

  This causes huge issues. If I were to have a Tpanel on the host form and a panel in the frames,
setting the OnClick event of a panel in a frame does not generate a unique name with the prepending
name of the frame instance along with the normal tag name you see.

 On top of all that, if I happen to already have a panelClick event already assigned in the HOST form
and creating a event for the panel in a frame causes the OI to point to the panelClick in the host
form..
 
 I hope you understand what I am saying here..

 it seems to be an old problem starting with Delphi, I found references of it on the net.

 Is there some trick to forcing the OI to generate a tag name with the prepending frame instance name
in the HOST form?

Also, is there some switch I can apply on the lines where I don't want the OI to branch and show or
allow access to ?

 what I mean is, lets say have several controls on the frame form but I don't want the HOST form in the OI to give viewable access or edit them, but only in the frame form will the OI allow access/view to them?
  For example {%HideFromHostformOI}

 I know its a lot of question but if these things are doable this would add crap loads of value to lazarus IDE!
The only true wisdom is knowing you know nothing

jamie

  • Hero Member
  • *****
  • Posts: 6091
Re: Tframes and user published propeties question.
« Reply #5 on: March 10, 2018, 04:24:11 pm »
specifically to be clearer about this, what I would like is a switch that can be on the line of a
component that has child controls that will cause the object inspector to not show them in the
host form OI.

 lets say you have a dynamic form setting on your main form that you can show when needed, the
OI when editing that main form should obey a switch on the line of the dynamic form indicating to not
show the component tree of that dynamic form or maybe just a few child members of that dynamic
form.
 
  This makes using Controls like Frames much cleaner where as you don't clutter up the host form OI
or allow access to these controls to avoid making mistakes of setting events or properties that shouldn't
get touched in the OI of the host form.

etc.
The only true wisdom is knowing you know nothing

Thaddy

  • Hero Member
  • *****
  • Posts: 14210
  • Probably until I exterminate Putin.
Re: Tframes and user published propeties question.
« Reply #6 on: March 10, 2018, 05:09:39 pm »
There are several tricks but none of them really a one stop solution because published properties can't be un-published:
- Compile the frame ( design mode! )code in {$M-} state and create any components on it in code.  Probably rename to something like TMyFrame = class (TCustomFrame)
- If you create the controls dynamically, use TCustomForm instead of TForm, use TCustomFrame instead of TFrame, etc... The TCustomXXX mostly have the same functionality, but w/o published properties.
- You can write a proxy class

Anyway, you can filter properties already in the IDE. Published can't be un-published. You can't have your cake and eat it.
« Last Edit: March 10, 2018, 05:16:09 pm by Thaddy »
Specialize a type, not a var.

ASerge

  • Hero Member
  • *****
  • Posts: 2223
Re: Tframes and user published propeties question.
« Reply #7 on: March 10, 2018, 05:15:47 pm »
Thanks, that's more on the lines of what I am doing using the Tlabel for the event object.
In TFrame special processing is provided for TActionList for the case of Parent change or inheritable frames.

jamie

  • Hero Member
  • *****
  • Posts: 6091
Re: Tframes and user published propeties question.
« Reply #8 on: March 10, 2018, 05:20:37 pm »
I will look at the {$M } switch but I don't think that is what I am looking for by the sounds of it.

that looks like a compiler switch..

I am looking for a IDE object inspector switch.

The only true wisdom is knowing you know nothing

jamie

  • Hero Member
  • *****
  • Posts: 6091
Re: Tframes and user published propeties question.
« Reply #9 on: March 16, 2018, 12:47:32 am »
Ok, I am going to steer this a little in a different direction..

 I have found that lazarus (object inspector) does not prepend the names of the Frame instance
so that a unique eventname is created for a child control inside a frame.

Lets look at this example here..
Code: Pascal  [Select][+][-]
  1. TMyFrame = Class(Tframe)
  2.   Panel:TPanel;
  3. End;
  4.  

And now the host form..
Code: Pascal  [Select][+][-]
  1.  Form1 = Class(Tform)
  2.   Panel :TPanel;
  3.   AFrame :TmyFrame;
  4. End;
  5.  

Now try to assign a unique OnClick handler for form1.Panel and one for Form1.AFrame.Panel
using the OI "Object inspector"

 The OI gives you PanelClick for Form1.Panel
 
 The OI also gives you PanelClick for the AFrame.Panel when doing this from the FORM1

 so what the OI does is simply points to the first PanelClick created instead of making a unique one
Aframe.PanelClick

 This is a problem because if I have several of these frames the OI does not prepend "Aframe" or what
ever the instance name is.

 I can create this manually in the form1 class and then direct the OI to use it, but shouldn't the OI
be able to do this?

 Online search tells me that Delphi does this..
 Aframe.PanelClick

 and if Panel has a child on it..
 AFrame.Panel.AchildNameClick

 isn't this how it should be done ?
The only true wisdom is knowing you know nothing

taazz

  • Hero Member
  • *****
  • Posts: 5368
Re: Tframes and user published propeties question.
« Reply #10 on: March 16, 2018, 12:53:52 am »
Ok, I am going to steer this a little in a different direction..

 I have found that lazarus (object inspector) does not prepend the names of the Frame instance
so that a unique eventname is created for a child control inside a frame.

Lets look at this example here..
Code: Pascal  [Select][+][-]
  1. TMyFrame = Class(Tframe)
  2.   Panel:TPanel;
  3. End;
  4.  

And now the host form..
Code: Pascal  [Select][+][-]
  1.  Form1 = Class(Tform)
  2.   Panel :TPanel;
  3.   AFrame :TmyFrame;
  4. End;
  5.  

Now try to assign a unique OnClick handler for form1.Panel and one for Form1.AFrame.Panel
using the OI "Object inspector"

 The OI gives you PanelClick for Form1.Panel
 
 The OI also gives you PanelClick for the AFrame.Panel when doing this from the FORM1

 so what the OI does is simply points to the first PanelClick created instead of making a unique one
Aframe.PanelClick

 This is a problem because if I have several of these frames the OI does not prepend "Aframe" or what
ever the instance name is.

 I can create this manually in the form1 class and then direct the OI to use it, but shouldn't the OI
be able to do this?

 Online search tells me that Delphi does this..
 Aframe.PanelClick

 and if Panel has a child on it..
 AFrame.Panel.AchildNameClick

 isn't this how it should be done ?
type a name directly on the event your self or if after the double click binds to an existing handler add the prefix you desire and press enter, OI will create that handler for you.
Good judgement is the result of experience … Experience is the result of bad judgement.

OS : Windows 7 64 bit
Laz: Lazarus 1.4.4 FPC 2.6.4 i386-win32-win32/win64

jamie

  • Hero Member
  • *****
  • Posts: 6091
Re: Tframes and user published propeties question.
« Reply #11 on: March 16, 2018, 03:17:48 am »
Ok, I'll give her a try! thanks..

The only true wisdom is knowing you know nothing

 

TinyPortal © 2005-2018