Recent

Author Topic: Compile Error  (Read 3274 times)

wjackson153

  • Sr. Member
  • ****
  • Posts: 267
Compile Error
« on: January 05, 2014, 07:23:36 am »
Not sure what has changed, but now compiler wants form1 included in my syntax

for example

Form1.label1.caption := 'Hello World';

I use to could just say

label1.caption := 'Hello World';

and it compiled just fine,   any idea why now it wont compile without form1. added to the syntax ?

Lazarus 1.1 r39490 CT FPC 2.7.1 i386-linux KDE
Linux Mint 14 KDE 4

taazz

  • Hero Member
  • *****
  • Posts: 5368
Re: Compile Error
« Reply #1 on: January 05, 2014, 07:26:20 am »
because the procedure you are using it in is not part of the TForm1 class probably.
Good judgement is the result of experience … Experience is the result of bad judgement.

OS : Windows 7 64 bit
Laz: Lazarus 1.4.4 FPC 2.6.4 i386-win32-win32/win64

wjackson153

  • Sr. Member
  • ****
  • Posts: 267
Re: Compile Error
« Reply #2 on: January 05, 2014, 07:34:37 am »
Code: [Select]
{ TForm1 }

  TForm1 = class(TForm)
    Button1: TButton;
    Button2: TButton;
    Edit1: TEdit;
    Label1: TLabel;



Label1  is purely in the the TForm Class

I beleive this to be a bug ???   perhaps random

I closed my project,  reopeded it  and now its working just fine, without the need to add form1
Lazarus 1.1 r39490 CT FPC 2.7.1 i386-linux KDE
Linux Mint 14 KDE 4

taazz

  • Hero Member
  • *****
  • Posts: 5368
Re: Compile Error
« Reply #3 on: January 05, 2014, 07:37:48 am »
not label1 the procedure you are accessing label1 is it part of the TForm1 class?
Good judgement is the result of experience … Experience is the result of bad judgement.

OS : Windows 7 64 bit
Laz: Lazarus 1.4.4 FPC 2.6.4 i386-win32-win32/win64

Leledumbo

  • Hero Member
  • *****
  • Posts: 8831
  • Programming + Glam Metal + Tae Kwon Do = Me
Re: Compile Error
« Reply #4 on: January 05, 2014, 12:47:03 pm »
Learn about identifier scope. You can access instance variables from instance methods directly, without the need to tell which object has the variable (same as prepending it with Self.) From another class' instance methods or pure procedure/function, you need to tell which object because they have no idea who has the variable.

 

TinyPortal © 2005-2018