Sign in Join

Live chat for Free Pascal, Lazarus, Delphi and every Pascal programmer.

Mailing lists / lazarus / 2010-04

typecast to an empty local class

2 messages · 2 people ·

Reply by email Subscribe to this list Your subscription

Read-only archive. Use j and k to move between messages.

Mattias Gaertner
to Juha Manninen: Hi Is this FPC behavior correct? Apparently it works in Delphi, at least ESS Model prog…
Show quoted text 24 lines
Hi Is this FPC behavior correct? Apparently it works in Delphi, at least ESS Model prog uses it heavily. The idea is to typecast controls like TForm and TTreeView to a local TCrackControl just to reach the protected TControl.OnMouseDown. type TCrackControl = class(TControl) end; // <-- empty local class var found: TControl; cc: TCrackControl; and later: // 'found' can be TForm or anything. cc:=TCrackControl(found); // <-- error cc.OnMouseDown(... In Lazarus / FPC it gives 'RunError(219)', or the system becomes unstable. (I think this created the previous problem instead of interfaces). The typecast should logically work because the controls inherit from TControl and OnMouseDown is defined there.

This trick is used at a few places in the Lazarus code for normal classes. I don't know if this works with interfaced classes.

Mattias

Reply by email

Juha Manninen

Hi

Is this FPC behavior correct?
Apparently it works in Delphi, at least ESS Model prog uses it heavily.

The idea is to typecast controls like TForm and TTreeView to a local TCrackControl just to reach the protected TControl.OnMouseDown.

  type
    TCrackControl = class(TControl) end;  // <-- empty local class
  var
    found: TControl;
    cc: TCrackControl;
and later:
  // 'found' can be TForm or anything.
  cc:=TCrackControl(found);  // <-- error
  cc.OnMouseDown(...

In Lazarus / FPC it gives 'RunError(219)', or the system becomes unstable. (I think this created the previous problem instead of interfaces).

The typecast should logically work because the controls inherit from TControl and OnMouseDown is defined there.

Juha

Reply by email