Component Notification Question

I have a non visual component that needs to do some work on a form after all of the components have been loaded. I assumed that overriding Loaded was the correct place to put this but the problem is that while the components have finished loading, some of the components still have csLoaded in their ComponentState. This causes problems for my code which needs this flag to be cleared. Is there anything I can hook into that happens after this and before the form is shown.
0
Dean
10/28/2013 11:04:27 PM
public.delphi.vcl.writing 510 articles. 0 followers. Follow

8 Replies
744 Views

Similar Articles

[PageSpeed] 49

Dean wrote:

> I have a non visual component that needs to do some work on a
> form after all of the components have been loaded.

That is not easy to do from inside a component.  Your best option is to post 
an asynchronous message to yourself and wait for the message queue to process 
that message at a later time.  I would use PostThreadMessage() to post a 
message to the Main Thread ID, and then use the TApplicationEvents.OnMessage 
event to catch the message.

> I assumed that overriding Loaded was the correct place to put this

Only if you were overriding it on the TForm itself, so it is called once 
the TForm has been fully loaded.  But if you are overriding Loaded() only 
on your component, then it is called only when your particular component 
is fully loaded, but other things outside of your component may still be 
loading.

> the problem is that while the components have finished loading, some of
> the components still have csLoaded in their ComponentState. This causes
> problems for my code which needs this flag to be cleared.

What exactly are you needing to do once everything has been loaded?

--
Remy Lebeau (TeamB)
0
Remy
10/28/2013 11:21:09 PM
Thanks for the quick response.

> {quote:title=Remy Lebeau (TeamB) wrote:}{quote}
> That is not easy to do from inside a component.  Your best option is to post 
> an asynchronous message to yourself and wait for the message queue to process 
> that message at a later time.  I would use PostThreadMessage() to post a 
> message to the Main Thread ID, and then use the TApplicationEvents.OnMessage 
> event to catch the message.

I was hoping you weren't going to say that.

> Only if you were overriding it on the TForm itself, so it is called once 
> the TForm has been fully loaded.  But if you are overriding Loaded() only 
> on your component, then it is called only when your particular component 
> is fully loaded, but other things outside of your component may still be 
> loading.

If I look at streaming code:

procedure TReader.FixupReferences;
var
  I: Integer;
begin
  DoFixupReferences;
  GlobalFixupReferences;
  for I := 0 to FLoaded.Count - 1 do TComponent(FLoaded[I]).Loaded;
end;

Then all of the components are definitely loaded, the only thing that could be a problem is that their Loaded methods haven't necessarily been called yet. They could be doing some work in there but thats unlikely to effect my logic.

> What exactly are you needing to do once everything has been loaded?

Modifying the size of the controls with ChangeScale. Unfortunately, TControl.ChangeScale checks for csLoading which is the problem.

---
Dean

Edited by: Dean Hill on Oct 29, 2013 1:47 AM
0
Dean
10/28/2013 11:47:27 PM
Dean wrote:

> I was hoping you weren't going to say that.

Why?  What is wrong with it?

> If I look at streaming code:
<snip>
> Then all of the components are definitely loaded

The code you showed is only for fixups.  When a streamed component has a 
property that references another component that has not been streamed yet, 
the reference is put in the fixup list so the reference can be resolved at 
a later time.  What you are not taking into account is other code in TReader 
that calls a component's Loaded() method, such as TReader.ReadRootComponent() 
immediately after the component is streamed, and by NotifyGlobalLoading() 
during global loading (not quite sure what triggers that).

So, when your component's Loaded() method is called, other components are 
NOT guaranteed to be loaded yet.  You can only assume that YOUR component 
has been fully loaded.  If you need to modify a component that has not been 
loaded yet, you have to delay your modification.

> Modifying the size of the controls with ChangeScale. Unfortunately,
> TControl.ChangeScale checks for csLoading which is the problem.

There is no notification to your component when other components have been 
loaded.  

--
Remy Lebeau (TeamB)
0
Remy
10/29/2013 12:53:11 AM
> {quote:title=Remy Lebeau (TeamB) wrote:}{quote}
> Why?  What is wrong with it?

It would add a lot of extra handles to the application as each instance of the component would create a windows handle. We have a large number of forms open at the same time. I suppose I could get clever and create a single shared handle for these sorts of things but it's extra work which doesn't really translate into a tangible benefit. It's far easier to just add a single method call to the afterconstruction on the forms where it is used.

> The code you showed is only for fixups.  When a streamed component has a 
> property that references another component that has not been streamed yet, 
> the reference is put in the fixup list so the reference can be resolved at 
> a later time.  What you are not taking into account is other code in TReader 
> that calls a component's Loaded() method, such as TReader.ReadRootComponent() 
> immediately after the component is streamed, and by NotifyGlobalLoading() 
> during global loading (not quite sure what triggers that).
> 
> So, when your component's Loaded() method is called, other components are 
> NOT guaranteed to be loaded yet.  You can only assume that YOUR component 
> has been fully loaded.  If you need to modify a component that has not been 
> loaded yet, you have to delay your modification.

Thanks for clearing that up. I should have looked at the code in much more detail.

---
Dean
0
Dean
10/29/2013 6:23:47 PM
Dean wrote:

> It would add a lot of extra handles to the application as each
> instance of the component would create a windows handle.

You do not need to add a window to your component, and I did not say to in 
my earlier replies.  You can use PostThreadMessage(), not PostMessage() like 
you are thinking, to post a message directly to the main message queue without 
using any windows at all.  There is a global MainThreadID variable in the 
System unit, that is the Thread ID to post to.  Then use TApplicationEvents 
to hook into the TApplication events (TApplicationEvents is a multicaster, 
so multiple TApplicationEvents objects can co-exist and receive the same 
events without worrying about trampling on each other).

For example:

{code}
type
  TMyComponent = class(...)
  private
    fAppEvents: TApplicationEvents;
    procedure AppMessage(var Msg: TMsg; var Handled: Boolean);
  public
    constructor Create(AOwner: TComponent); override;
  end;

constructor TMyComponent.Create(AOwner: TComponent);
begin
  inherited;
  fAppEvents := TApplicationEvents.Create(Self);
  fAppEvents.OnMessage := AppMessage;
  PostThreadMessage(MainThreadID, WM_MY_LOADED_MESSAGE, 0, LPARAM(Self));
end;

procedure TMyComponent.AppMessage(var Msg: TMsg; var Handled: Boolean);
begin
  if (Msg.message = WM_MY_LOADED_MESSAGE) and
    (TMyComponent(Msg.lParam) = Self) then
  begin
    Handled := True;
    // everything is loaded now, do something...

    // optionally:
    // FreeAndNil(fAppEvents);
  end;
end;
{code}

--
Remy Lebeau (TeamB)
0
Remy
10/29/2013 7:51:28 PM
> {quote:title=Remy Lebeau (TeamB) wrote:}{quote}
> You do not need to add a window to your component, and I did not say to in 
> my earlier replies.  You can use PostThreadMessage(), not PostMessage() like 
>
> .......... Snip ..........
> 
> --
> Remy Lebeau (TeamB)

Thank you very much. I didn't know you could use the TApplicationEvents as a multicaster. I just assumed you were talking about hooking something into the application at that point. Will test it out and see how it goes.

---
Dean
0
Dean
10/29/2013 9:40:46 PM
> {quote:title=Dean Hill wrote:}{quote}
> > {quote:title=Remy Lebeau (TeamB) wrote:}{quote}
> > You do not need to add a window to your component, and I did not say to in 
> > my earlier replies.  You can use PostThreadMessage(), not PostMessage() like 

Ok, tested and it sort of works. Everything goes as planned except it only does its business after the form is shown and not before. So the form is painted once and then painted again after it has been updated which is a problem as I need it to be sorted out before it's displayed. I should have realized as the message is going to go to the back of the message queue for the application. It's not the end of the world as I have a workaround which is to add a single line to the form source code. It would be n
ice if Emb could add something like this in the future. I can see how the people that build language components could be pulling their hair out.

Thanks for the help in any case as I learned something that I am sure will come in handy in the future.

---
Dean
0
Dean
10/29/2013 10:44:43 PM
Dean wrote:

> Ok, tested and it sort of works. Everything goes as planned except it
> only does its business after the form is shown and not before. So the
> form is painted once and then painted again after it has been updated
> which is a problem as I need it to be sorted out before it's displayed.

Then you are not going to be able to handle this inside your component alone, 
since you are looking for logic that really belongs at the Form layer instead.

> It would be nice if Emb could add something like this in the future.

There is not much need for most component vendors to receive a component-level 
notification when the parent Form/Frame/DataModule is fully loaded, so I 
don't really see Embarcadero adding something for it anytime soon.

--
Remy Lebeau (TeamB)
0
Remy
10/29/2013 11:16:41 PM
Reply:

Similar Artilces:

ANN: Bricksoft IM VCL Component v8.2 released. All components support Delphi 2009!
All components support Delphi 2009! Please download the trial version(http://www.imcomponents.com/bsimtrial.zip) if you like. -- Bricksoft Support Bricksoft IM(MSN+YAHOO+AIM+ICQ+Jabber/GTalk) SDK For NET/VCL/COM/SOAP - http://www.imcomponents.com/ "Jianmin Wu" <nospam@nospam.com> wrote in message news:72535@forums.codegear.com... > All components support Delphi 2009! with D2009 support, do you still require TNT controls for unicode ? Also do you have any plans to support emoticons ? Regards, Danny Component and demo for D2009 don't need TNT cont...

How to uninstall a VCL Component in Delphi 2007?
Guys How do I uninstall a VCL Component in Delphi 2007? Mark Moss Nevermind I figured out how to do it. Mark Moss "Mark Moss" <markemoss@comcast.net> wrote in message news:245205@forums.embarcadero.com... > Guys > > > How do I uninstall a VCL Component in Delphi 2007? > > > Mark Moss ...

Delphi 2007 Component Installation Question
The members of our development group use either Delphi 2006 or Delphi 2007 to develop software. A couple people ended up with 2007 because we could not obtain 2006 anymore at the time. One issue that we're running into is with a component that we have specifically for our development needs. The component compiles fine and installs fine in Delphi 2006. However, with Delphi 2007, the component will compile fine, but when it tries to install, we keep getting the error message that states the following: "Can't load package <folder location>/<componentname>.bpl. Not...

Spreadsheet component for use in Delphi VCL 2010
Good day I have been using the Flexcel component for reading and writing Excel spreadsheets in my Delphi VCL projects for some while and have been very happy. Unfortunately, though, a version for use with Excel 2007 format files (.XLSX) has been promised for years now but just never arrives and I have reached a stage where I just have to update some of my software. Can any body suggest alternatives and comment on their experience with these? I have no objection to buying a component although all my programs are for academic use by myself and colleagues/friends so cheaper would...

MAC OS-style VCL components for Delphi?
Hi all, I saw an application that I am interested in porting from C to Delphi (http://thirdcog.eu/apps/cfxr) and found it comes with a win32 version, using IMHO yucky controls, and a nice shiny native MAC version (Coca, etc). I really like the look, of the Mac port...I was wondering if there are any VCL controls (preferably free) that can make nice buttons, sliders, etc. like in that MAC screenshot? I'm not worried if they don't operate exactly like MAC ones, I mainly like the look :) I have tried googling but no luck so far :( cheers, Paul www.alphaskins...

.net component to Delphi component ?
Hello, Is there a way to use .net component inside Delphi ? Thanks On Tue, 18 Nov 2008 13:16:37 -0800, isaac sam wrote: > Is there a way to use .net component inside Delphi ? http://www.managed-vcl.com/ has some libraries for this. -- Marc Rohloff [TeamB] marc -at- marc rohloff -dot- com Marc Rohloff wrote: > On Tue, 18 Nov 2008 13:16:37 -0800, isaac sam wrote: > >> Is there a way to use .net component inside Delphi ? > > http://www.managed-vcl.com/ has some libraries for this. > I was hoping for a free tool but thanks On Tue, 18 Nov 2008...

Delphi VCL components properties history articles
Hi, i would like to know where i can found Delphi VCL components properties history information because i need to know from wich Delphi version a property exists or from wich version a protected procedure was marcked with "virtual" command from a standard component. Thanks, Maurício "Julio Pião" <=?Utf-8?Q?Julio_Pi=C3=A3o?=> wrote in message news:292952@forums.embarcadero.com... > i would like to know where i can found Delphi VCL components > properties history information AFAIK, that kind of list does not exist anywhere. > i ...

skin component for VCL.NET Delphi 2007 ?
I'm trying to find out a component which skin forms automatically. It needs to be VCL.Net component for Delphi 2007. I tried to find one on the web with no success. There are many for VCL but not for VCL.Net. Thanks, Rumen ...

Component to host VCL component
In the old days, when FireMonkey was still VGScene, we had a nice component that would host any good old VCL component. Very practical. How is this achieved with FireMonkey? I'm not interested in any cross-platform stuff, just want to use it on Windows. ...

Which VCL components are (not) included in Delphi XE5 starter?
I currently own RAD Studio 2010 Professional with which I have developed a few Delphi applications, mainly for personal use. I only develop for Windows 32-bit platform and do NOT use Database components, I consider switching from Delphi 2010 Professional to Delphi XE5 Starter Edition and would like to know if my current applications can be compiled with Delphi XE5 Starter. Is there a way to check this _before_ buying Delphi XE5 ? My main concern is that some VCL components from Delphi 2010 Professional are not included in Delphi XE5 Starter Edition, but I cannot find a list which components...

Probably dumb questions about migrating my existing VCL component to .NET
I have a product that generates source code (for most popular Windows compilers) for USB device developers. I have a VCL component (written in 32-bit Delphi) that I have provided to my customers for years, without source code, in two forms: a) as a VCL for Delphi users, and b) as an ActiveX for everybody else. I provide the ActiveX control with a license file, so that only my registered customers can use it in a development environment, not their end users. Recently several customers have tried to use this with MS Express 2008 compilers on 64-bit machines, and they find that the ...

Delphi XE8 Send Notification from Parse using VCL app
Hello, I am learning the new Baas technology with XE8. I created a small app to receive notification on Android mobiles using Parse. Everything is working fine when the notification message is sent from Parse web site. However when my VCL app send the notification with BackendPush component, nothing is coming in mobile phone. The messages are sending correctly because I can see them on Parse site. Their status is different than the one sent from Parse . Here are my VCL messages Status on Parse: Type: API, target: Chanels. When sent on Parse site: Type : Campaign, Target: Everyone...

SEPA components for Delphi with Source Code (Delphi 5
Hi all, in the european union change next year the Bankingformat to the SEPA Format. All peoples and companies must change the bankingssoftware and the costumer data form acountnummers in the new IBAN and BIC numbers. See: http://www.arma-it.de/shop/artikelueber.php?wgruppeid=211&wgruppe_offen=211 Functions: - generate SEPA XML'S - Calc IBAN - BIC Database (DE,AT and CH) Questions: vertrieb@arma-it.de PS: Bankinssoftware for Develpoers (Germany only) http://www.arma-it.de/shop/artikelueber.php?wgruppeid=212&wgruppe_offen=212 El 26/10/13 21:38, A...

Actuall thread about vcl classes / components in C++ for use with delphi...
Hi All, I wanted to follow the topic that appears as a 'sub-thread' above... suspecting it would die... I'm sure many of us are interested in this topic. ( by 'sure' I mean absolutely certain...) It also brings to my mind the question, does anyone know of any references for us semi-delphi-literate C++ programmers that would like to read/write/modify delphi stuff? Thanks Everyone, (you know who you are... B) Bruce ...

Web resources about - Component Notification Question - public.delphi.vcl.writing

Fire alarm notification appliance - Wikipedia, the free encyclopedia
A fire alarm notification appliance is an active fire protection component. A notification appliance may use audible, visible, or other stimuli ...

Facebook To Allow Users To Opt Out Of Notifications Directly Via Drop-Down Menu
Facebook continues to give its users more and easier controls over the notifications they receive, announcing Wednesday that it will implement ...

Facebook Introduces Notify, a News App Designed to Make Your Other Notifications Obsolete
... Notify, which will alert users with information from media companies including CNN, The Weather Channel, Fox Sports and Fandango. Its notifications ...

Facebook Really Doesn’t Want You to Miss a Post or Notification
Facebook is apparently testing new ways to get you to read content you may have missed . Some users are seeing notifications (right) of group ...

KakaoTalk updated with support for interactive notifications and 3D Touch
... prefer it over the aforementioned rival apps or even more popular messaging apps like Facebook Messenger and WhatsApp . Interactive notifications ...

Apple invention lets users control time-sensitive notifications with their eyes
... so-called "gaze detection" technology, particularly as a means to control certain user interface events like autocorrect pop-ups, app notifications ...

How to use your iPhone’s camera flash as a notification light
... was plenty to love about BlackBerry phones back then, but there was one feature in particular that people hated to love: the flashing LED notification ...

Apple's new patent wants you to control notifications with your eyes
Notifications on your iPhone might one day respond to your gaze. Apple has been granted a patent for the "delay of display event based on user ...

Couture Smart Jewelry Buzzes When You Get Notifications
... you slap on it. Instead, they create wearables that look like jewelry first, tech second, while adding in another wrinkle — selective notifications, ...

Pro Tip: The secret meaning of Apple Watch notifications shapes
If you’ve not paying really close attention to your Apple Watch notifications, you might have missed out on a really subtle and clever design ...

Resources last updated: 12/4/2015 7:47:03 AM