Recent

Author Topic: Is there a wiki article or some guide about converting a form into a component?  (Read 1008 times)

vfclists

  • Hero Member
  • *****
  • Posts: 1146
    • HowTos Considered Harmful?
Is there a wiki article or some online guide about converting a form into a component, whether with Delphi or FreePascal?

I'm not quite sure if I remember this correctly, but there seems to be a way of turning a form into a component.

I'm not sure whether doing so enables the form to be designed in the IDE, but at least the component properties can be set and after the form is created at runtime it can probably use some of its properties to configure itself.

Searching for "create a component from a form" doesn't produce any meaningful results.
Lazarus 3.0/FPC 3.2.2

Joanna from IRC

  • Hero Member
  • *****
  • Posts: 1208
Do you mean like a customized descendant of tform like

Tmyform = class (tform)
{
Overridden methods here
}
End;
✨ 🙋🏻‍♀️ More Pascal enthusiasts are needed on IRC .. https://libera.chat/guides/ IRC.LIBERA.CHAT  Ports [6667 plaintext ] or [6697 secure] channel #fpc  #pascal Please private Message me if you have any questions or need assistance. 💁🏻‍♀️

vfclists

  • Hero Member
  • *****
  • Posts: 1146
    • HowTos Considered Harmful?
Do you mean like a customized descendant of tform like

Tmyform = class (tform)
{
Overridden methods here
}
End;

No. More like a regular form I want to turn into a component so I can set some of its properties through the Object Inspector.

I'm not sure whether I should create a non-visual component and use it to create the form at runtime and set the forms properties through the component.
Lazarus 3.0/FPC 3.2.2

Joanna from IRC

  • Hero Member
  • *****
  • Posts: 1208
I will be interested to know how that is done
✨ 🙋🏻‍♀️ More Pascal enthusiasts are needed on IRC .. https://libera.chat/guides/ IRC.LIBERA.CHAT  Ports [6667 plaintext ] or [6697 secure] channel #fpc  #pascal Please private Message me if you have any questions or need assistance. 💁🏻‍♀️

jamie

  • Hero Member
  • *****
  • Posts: 6735
Tframe ?
The only true wisdom is knowing you know nothing

vfclists

  • Hero Member
  • *****
  • Posts: 1146
    • HowTos Considered Harmful?
Tframe ?

TFrame doesn't provide what I need, which is setting and reading properties at runtime.

That is why a TForm is preferable.

https://forum.lazarus.freepascal.org/index.php/topic,31680.0.html
Lazarus 3.0/FPC 3.2.2

Joanna from IRC

  • Hero Member
  • *****
  • Posts: 1208
It is very easy to read and set most properties at runtime for a form created at runtime. Just use your autocomplete {ctrl space} to access the properties. You can view everything in the list no problem  8-)

Oh maybe you mean you want to access the properties of the form while program is running? I don’t know how to do that besides creating a gui that mimics the object inspector. And having the change events in gui affect the properties programmatically.
« Last Edit: October 02, 2024, 10:45:54 am by Joanna »
✨ 🙋🏻‍♀️ More Pascal enthusiasts are needed on IRC .. https://libera.chat/guides/ IRC.LIBERA.CHAT  Ports [6667 plaintext ] or [6697 secure] channel #fpc  #pascal Please private Message me if you have any questions or need assistance. 💁🏻‍♀️

MarkMLl

  • Hero Member
  • *****
  • Posts: 8023
TFrame doesn't provide what I need, which is setting and reading properties at runtime.

That is why a TForm is preferable.

https://forum.lazarus.freepascal.org/index.php/topic,31680.0.html

Rubbish. You can do anything you want to an instantiated TFrame and its contents at runtime, what you /can't/ (or at least shouldn't) do is put one on your form at design time and fiddle with the content from the IDE.

This is discussed regularly, and /far/ more recently than the ancient thread you've cited. Frames are particularly useful if you want to set up some sort of tabbed notebook each page with the same starting content, but the procedure is to design the frame (using the IDE) but to instantiate and manipulate it entirely at runtime.

What you mustn't do is instantiate and manipulate using the IDE, because you risk getting yourself into a situation where you have to edit the .lfm as text to get rid of unwanted properties.

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

Joanna from IRC

  • Hero Member
  • *****
  • Posts: 1208
Quote
What you mustn't do is instantiate and manipulate using the IDE, because you risk getting yourself into a situation where you have to edit the .lfm as text to get rid of unwanted properties.
I’ve learned that the hard way . Assigning event proedures causes some spectacular crashes  :D
✨ 🙋🏻‍♀️ More Pascal enthusiasts are needed on IRC .. https://libera.chat/guides/ IRC.LIBERA.CHAT  Ports [6667 plaintext ] or [6697 secure] channel #fpc  #pascal Please private Message me if you have any questions or need assistance. 💁🏻‍♀️

vfclists

  • Hero Member
  • *****
  • Posts: 1146
    • HowTos Considered Harmful?
<snip>

Oh maybe you mean you want to access the properties of the form while program is running? I don’t know how to do that besides creating a gui that mimics the object inspector. And having the change events in gui affect the properties programmatically.

I use an Object Inspector based component to set the properties at runtime and back then when I tried to use it to set the properties of objects on the frames it didn't work because they weren't exposed.

I don't know if things have changed since then as I replaced the frames with forms to gain that functionality.
Lazarus 3.0/FPC 3.2.2

vfclists

  • Hero Member
  • *****
  • Posts: 1146
    • HowTos Considered Harmful?
TFrame doesn't provide what I need, which is setting and reading properties at runtime.

That is why a TForm is preferable.

https://forum.lazarus.freepascal.org/index.php/topic,31680.0.html

Rubbish. You can do anything you want to an instantiated TFrame and its contents at runtime, what you /can't/ (or at least shouldn't) do is put one on your form at design time and fiddle with the content from the IDE.

This is discussed regularly, and /far/ more recently than the ancient thread you've cited. Frames are particularly useful if you want to set up some sort of tabbed notebook each page with the same starting content, but the procedure is to design the frame (using the IDE) but to instantiate and manipulate it entirely at runtime.

What you mustn't do is instantiate and manipulate using the IDE, because you risk getting yourself into a situation where you have to edit the .lfm as text to get rid of unwanted properties.

MarkMLl

I use an Object Inspector based component to set the properties at runtime and back then when I tried to use it to set the properties of objects on the frames it didn't work because they weren't exposed.

I don't know if things have changed since then as I replaced the frames with forms to gain that functionality.

Have there been changes in Lazarus which expose the properties of objects in frames to the objects since then? By that I mean at runtime.
Lazarus 3.0/FPC 3.2.2

MarkMLl

  • Hero Member
  • *****
  • Posts: 8023
Have there been changes in Lazarus which expose the properties of objects in frames to the objects since then? By that I mean at runtime.

If it didn't work would I really be telling you that it was the only safe way to do it?

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

Joanna from IRC

  • Hero Member
  • *****
  • Posts: 1208
I use an Object Inspector based component to set the properties at runtime and back then when I tried to use it to set the properties of objects on the frames it didn't work because they weren't exposed.

I don't know if things have changed since then as I replaced the frames with forms to gain that functionality.
That makes sense that there would be something like an object inspector that can be used at runtime. Can you show how you do it? I’m curious.
Also the properties of controls are usually accessible at runtime however the form is the only controls that is intended to be freestanding so maybe that’s why you can’t use frame for this.
✨ 🙋🏻‍♀️ More Pascal enthusiasts are needed on IRC .. https://libera.chat/guides/ IRC.LIBERA.CHAT  Ports [6667 plaintext ] or [6697 secure] channel #fpc  #pascal Please private Message me if you have any questions or need assistance. 💁🏻‍♀️

mas steindorff

  • Hero Member
  • *****
  • Posts: 550
I use an Object Inspector based component to set the properties at runtime and back then when I tried to use it to set the properties of objects on the frames it didn't work because they weren't exposed.

I don't know if things have changed since then as I replaced the frames with forms to gain that functionality.

Have there been changes in Lazarus which expose the properties of objects in frames to the objects since then? By that I mean at runtime.
I have just created a frame whos Tlabels, Tedit and Tcombo box components can be changed at runtime.  I also can change the visibility of these and TEdits as well.  I did expose these things though my own procedures and properties so I could add smarts (like both Tedit & matching Tlable are shown or not shown) but before I did, I was accessing the properties directly though the parent.

The IDE does this smart change too. Just set the index of a combo box to zero and watch the text field get updated to the 1st item in the list. I don't believe you will not get this smart multi-property action if you do the same thing at runtime.
windows 10 &11, Ubuntu 21+ IDE 3.4 general releases

Joanna from IRC

  • Hero Member
  • *****
  • Posts: 1208
I think he wants something like the object inspector available at runtime so he can change the properties through a gui interface while the program is running. Am I right?
✨ 🙋🏻‍♀️ More Pascal enthusiasts are needed on IRC .. https://libera.chat/guides/ IRC.LIBERA.CHAT  Ports [6667 plaintext ] or [6697 secure] channel #fpc  #pascal Please private Message me if you have any questions or need assistance. 💁🏻‍♀️

 

TinyPortal © 2005-2018