Missing TLabel component compiles fine and does not crash when running ... bug.

Hi,

I'd like to report a bug ... but I don't have the time to find out the proper channels. I hope some smart guy here can quickly do it ...

The bug: if a TLabel component is missing from the dfm file (like in an old project inherited from svn where lots of bad things happend), but it is still declared in the source .pas file, there is not compile error (first bug). Also if you only work on that non-existing label's Caption in the code, it still works, even though if you put the mouse on buggy code over the label's name, it says correctly that it is nil. So the second bug is that a nil TLabel.Caption still doesn't crash at run time. I'm not happy with "it's a feature" :-) ...

Here's the dfm:

object Form1: TForm1
Left = 0
Top = 0
Caption = 'Form1'
ClientHeight = 183
ClientWidth = 459
Color = clBtnFace
Font.Charset = DEFAULT_CHARSET
Font.Color = clWindowText
Font.Height = -11
Font.Name = 'Tahoma'
Font.Style = []
OldCreateOrder = False
PixelsPerInch = 96
TextHeight = 13
object Edit1: TEdit
Left = 60
Top = 42
Width = 121
Height = 21
TabOrder = 0
Text = 'Edit1'
OnKeyDown = Edit1KeyDown
end
end

and here is the source:

unit Unit1;

interface

uses
Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants, System.Classes, Vcl.Graphics,
Vcl.Controls, Vcl.Forms, Vcl.Dialogs, Vcl.StdCtrls;

type
TForm1 = class(TForm)
Edit1: TEdit;
Label1: TLabel;
procedure Edit1KeyDown(Sender: TObject; var Key: Word; Shift: TShiftState);
private
{ Private declarations }
public
{ Public declarations }
end;

var
Form1: TForm1;

implementation

{$R *.dfm}

procedure TForm1.Edit1KeyDown(Sender: TObject; var Key: Word; Shift: TShiftState);
begin
if Label1.Caption = '' then
MessageBeep(0);
end;

end.

I appreciate someone else reports this, thank you very much

Parents
  • What version are you using?

    In 10.4, if I drop your code as is then as soon as I try compile or run I get the message

    ---------------------------
    Error
    ---------------------------
    Field Form1.Label1 does not have a corresponding component. Remove the declaration?
    ---------------------------
    Yes No Cancel Help
    ---------------------------

Reply Children
No Data