Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Who paints TTimer at design time?

Who paints TTimer at design time ?

When using the Delphi IDE's form designer, when you drop a TTimer on the form, the component is visible at design time (but, of course, non-visual at runtime).

The TTimer class is defined in unit ExtCtrls, so of course I did read the TTimer source code in that unit.

I was expecting to see something like this:

procedure TTimer.Paint;
begin
  if csDesigning in ComponentState then
    with Canvas do
    begin
      // Paint the design-time appearance of TTimer here:

      // ... code ...

    end else begin end; // no painting at runtime.
end;

But I was surprised to see no such code!

The TTimer component has this private field: FWindowHandle: HWND;, but that is only used to receive the WM_Timer message from windows itself. It is not used to paint anything, even at design time. And no canvas either.

While reading the TTimer source code, I could not find anything related to design time painting.

So the question is: what code and where is responsible to paint the TTimer's design time appearance on the form in the form designer of the Delphi IDE itself.

Now, if someone wonders why I ask this question, here's some information about that:

Elsewhere on StackOverflow someone asked if it is possible to load a .dfm file at runtime. Someone answered: "No, it is not possible".

But that is not exactly true. I have written some code to do exactly this: load "someform.dfm" from disk and create such form at runtime. That is possible, but the nuisance is that then you need to write code like this:

procedure RegisterNecessaryClasses;
begin
  RegisterClass(TfrmDynaForm);
  RegisterClass(TPanel);
  RegisterClass(TMemo);
  RegisterClass(TTimer);
  RegisterClass(TListBox);
  RegisterClass(TSplitter);
  RegisterClass(TEdit);
  RegisterClass(TCheckBox);
  RegisterClass(TButton);
  RegisterClass(TLabel);
  RegisterClass(TRadioGroup);
end;

This is just a first example that lets me load and present one particular form without errors. But, as soon as some other form contains, for example: TSpeedbutton, then the above procedure needs to be edited to add this line:

  RegisterClass(TSpeedbutton);

Skip that, and you'll have a "class Txxx not found" -exception.

Another problem is that even after I added code to find any TTimer components in the dfm to load, and I manually have set csDesigning in the ComponentState of that TTimer instance, the TTimer still stays invisible.

So what (else) do I need to do to make the TTimer visible the same way it is visible in the Delphi IDE's form designer?

like image 848
mika Avatar asked Apr 19 '14 19:04

mika


1 Answers

Non-visual components have no Paint method and so are not capable of painting themselves.

Who paints TTimer at design time?

The IDE paints the representation of non-visual components.

So what (else) do I need to do to make the TTimer visible the same way it is visible in the Delphi IDE's form designer?

You have to paint it in your code. Non-visual components will not paint themselves.

like image 59
David Heffernan Avatar answered Nov 07 '22 10:11

David Heffernan