Recent

Author Topic: Designer issues with specialized TFrame classes.  (Read 511 times)

papelhigienico

  • New Member
  • *
  • Posts: 20
    • PascalSCADA
Designer issues with specialized TFrame classes.
« on: February 04, 2025, 11:24:50 pm »
Hi everyone!

I'm creating a new control for PascalSCADA that will mimic a functionality of other engineering software in Lazarus. Lazarus has a similar feature (Frames). Knowing this, I started from TFrame, trying to specialize it to get new functions, but in this way, I'm doing something wrong in the process.

What I did:

1) Created the specialized TFrame class with the desired properties.

Code: Pascal  [Select][+][-]
  1.   TFaceplateFrame = class(TFrame)
  2.   private
  3.     ffaceplatetag: TPLCStruct;
  4.   protected
  5.     procedure setfaceplateTag(AValue: TPLCStruct);
  6.   published
  7.     property FaceplatePLCTag: TPLCStruct read ffaceplatetag write setfaceplateTag;
  8.   end;
  9.  

2) Registered a Lazarus project file descriptor using the function RegisterProjectFileDescriptor. The class TFaceplateFrameFileDescriptor inherits from TFileDescPascalUnitWithResource. Below is the constructor of the file descriptor:

Code: Pascal  [Select][+][-]
  1. constructor TFaceplateFrameFileDescriptor.Create;
  2. begin
  3.   inherited Create;
  4.   Name := 'FaceplateFrame'; // do not translate this
  5.   ResourceClass := TFaceplateFrame;
  6.   RequiredPackages := 'pascalscada_hmi';
  7.   UseCreateFormStatements := True;
  8. end;
  9.  

What I expect:
After doing the previous steps, when I create a new TFaceplateFrame (using Lazarus menu File -> New, then choosing FaceplateFrame), the property FaceplatePLCTag should be visible on newly created TFaceplateFrame instances, in the TFaceplateFrame designer or even in TFaceplateFrame instances inside forms.

This happens on a freshly created TFaceplateFrame, but if I close and reopen the project, the FaceplatePLCTag property of my FaceplateFrame instances is lost and does not appear in the Object Inspector anymore.

So, someone can tell me what I'm doing wrong?

MarkMLl

  • Hero Member
  • *****
  • Posts: 8234
Re: Designer issues with specialized TFrame classes.
« Reply #1 on: February 05, 2025, 12:10:07 pm »
Only edit the initial TFrame descendant. If you attempt to do anything to one which has been instantiated onto a form you'll end up in a heck of a mess, which might include having to fix up your .lfm file with a text editor.

The fact that instantiated frames aren't treated (at least by default) as read-only is a longstanding niggle with a number of us, who have learned to grit our teeth and work around the issues by only instantiating (e.g. into a panel or tabbed control) at runtime.

I'd suggest not referring to "specialisation" in this context, since the term's been coopted to refer to generics etc.

MarkMLl
MT+86 & Turbo Pascal v1 on CCP/M-86, multitasking with LAN & graphics in 128Kb.
Logitech, TopSpeed & FTL Modula-2 on bare metal (Z80, '286 protected mode).
Pet hate: people who boast about the size and sophistication of their computer.
GitHub repositories: https://github.com/MarkMLl?tab=repositories

papelhigienico

  • New Member
  • *
  • Posts: 20
    • PascalSCADA
Re: Designer issues with specialized TFrame classes.
« Reply #2 on: February 05, 2025, 09:26:28 pm »
Hi MarkMLl!

Thank you by your advises. I'm looking for the best way to implement the desired feature, and for now, extend a TFrame still the best option. Furthermore, I discovered that I have to register the extented TFrame class into the IDE Form designer, doing something like this:

Code: Pascal  [Select][+][-]
  1. uses ..., FormEditingIntf;
  2.  
  3. procedure Register;
  4. begin
  5.  FormEditingHook.RegisterDesignerBaseClass(TFaceplateFrame);
  6. end;
  7.  


Doing this, I was able to see the new properties added to my TFrame descendant class, in Frame design or in frame instances, even across IDE reinitializations.

Now I have to figure out how to hide a propety in frame design time, but make property visible when Object Inspector is handling a FaceplateFrame instance.

And sorry by my translations mistakes. I'll try don´t use "specialize" when I want to say "extend".

 

TinyPortal © 2005-2018