Monday, October 5, 2009

Compiler complains

Here's a short list of frequent compiler errors and examples of how to produce and solve them

E1038 Unit identifier '%s' does not match file name
- create a new project press F12 to switch to code editor, press CTRL+Home and change unit1 to anything else i.e. unit_E1038;
solve
- the unit identifier and the unit file name must perfectly match(case sensitive), i.e. if the identifier after unit keyword is myFavoritUnit then the file name must be myFavoritUnit.pas.

E2003 Undeclared identifier '%s'
problem You must declare the identifier and it's type before you can use it
procedure produce_E2003;
begin
  ShowMessage(myUndeclaredIdentifier);
end;
solve
procedure solve_E2003;
var
  myDeclaredIdentifier: String;
begin
  myDeclaredIdentifier := 'I love Delphi';
  ShowMessage(myDeclaredIdentifier);
end;

E2004 Identifier redeclared '%s'
procedure produce_E2004;
var
  myRedeclaredIdentifier: Integer;
  myRedeclaredIdentifier: Integer;
begin
...
end;
solve
procedure solve_E2004;
var
  mySingleTimeDeclaredIdentifier1: Integer;
  mySingleTimeDeclaredIdentifier2: Integer;
begin
...
end;

E2005 '%s' is not a type identifier
This error is shown when you try to declare a variable of an unknown type
procedure produce_E2005;
var
  aVariable: MySuperClass; (* <-- MySuperClass is not defined *)
begin
end;
solve
type
  MySuperClass = class (* <-- MySuperClass is now defined *)
  (* ... *)
  end;
procedure solve_E2005;
var
  aVariable: MySuperClass;
begin
end;
E2009/E2010 Incompatible type(s) '%s' (and '%s')
procedure produce_E2009_E2010;
var
  myIntegerVariable: Integer;
begin
  myIntegerVariable := 'a string cannot be assigned to an integer variable';
end;
solve
procedure solve_E2009_E2010;
var
  myIntegerVariable: Integer;
begin
  myIntegerVariable := 2009;
end;
E2014 Statement expected, but expression of type '%s' found
procedure produce_E2014;
var
  myInteger: Integer;
begin
  2000+14;
end;
solve
procedure solve_E2014;
var
  myInteger: Integer;
begin
  myInteger := 2000+14;
end;
E2015 Operator not applicable to this operand type Source: Delphi Help
program Produce;
var
  P: ^Integer;
begin
  if P and P^ > 0 then
    Writeln('P points to a number greater 0');
end.
solve
program Solve;
var
  P: ^Integer;
begin
  if (P <> nil) and (P^ > 0) then
    Writeln('P points to a number greater 0');
end.
E2017 Pointer type required
procedure produce_E2017;
var
  x: TForm;
begin
  x^.ShowModal;
end;
solve
procedure solve_E2017;
var
  x: TForm;
begin
  x.ShowModal; (* just remove the ^ symbol *)
end;
E2023 Function needs result type
function produce_E2023; (* no result type!! *)
begin
end;
solve
function solve_E2023: Integer;(* or any other type *)
begin
end;
E2025 Procedure cannot have a result type
procedure produce_E2025: Integer;
begin
end;
solve
procedure solve_E2025; (* I removed ": integer" *)
begin
end;
E2030 Duplicate case label
procedure produce_E2030;
var
  aCase: Integer;
begin
  case aCase of
    0: (* do something *);
    0: (* here's the duplicate case label "0" *);
  end;
end;
solve
procedure solve_E2030;
var
  aCase: Integer;
begin
  case aCase of
    0: (* do something *);
    4: (* changed from "0" to "4" *);
  end;
end;

No comments:

Post a Comment

Blogroll(General programming and Delphi feeds)