0

I am migrating my Delphi 5 application to Delphi XE3. I am totally new to XE3.

While compiling application I am getting error 'Undeclared Identifier Interace_Info'.

Code is like below:

abc.inc:

Interace_Info = packed record
iflag: ulong;
end;

.

Unit unit2
type
ulong: DWORD;
{$include abc.inc}
end.

.

Unit unit1
uses unit2;
type
Tlocal= array[0..10] of Interace_Info;

Where Interace_Info is declared in 'abc.inc' file.

I am not able to open any file which is mentioned in uses section by pressing Ctrl+left mouse button. I am getting error "Unable to locate file 'winapi.unit2.pas' ".

What is the solution to this?

Thanks

Remy Lebeau
  • 555,201
  • 31
  • 458
  • 770
Nalu
  • 1,107
  • 4
  • 20
  • 43
  • Fix `unit2` to actually contain the code, and remove the `{$Include abc.inc}` line, and then fix the `unit2` uses clause to remove `WinAPI`, which has been obsolete since support for 16-bit Windows programs disappeared. – Ken White Nov 15 '12 at 21:06
  • It is perfect valid to continue using an .inc file. Its contents will get merged with the .pas file that is including it. What does the content of abc.inc actually look like? Changes are it is not declaring `Interface_Info` correctly, so it doesn't get compiled into User2's .dcu file for Unit1 to use. – Remy Lebeau Nov 15 '12 at 21:25
  • `Winapi` is a new "Unit Scope Name" in XE3. Unless you are writing cross-platform code, it is valid and common to use `Winapi` in uses clauses (eg: `uses Winapi.Windows, Winapi.Messages`, etc). See the filenames in the `$(BDS)\source\rtl\win` folder. – Remy Lebeau Nov 15 '12 at 21:27
  • is it means before each unit file in uses cluase i need to add winapi.? – Nalu Nov 15 '12 at 21:40
  • No, it is only that WinApi (and others) is prefixed to Unit2 when no Unit2.pas or unit2.dcu is found. – Uwe Raabe Nov 15 '12 at 21:42
  • 1
    Looks like there is a missing interface and implementation declaration in unit2. – LU RD Nov 15 '12 at 21:45
  • @LU The published code will not compile in Delphi 5 also, so IMHO the problem is not the migration to XE3, but the lack of proper pascal constructs for any Delphi version. – jachguate Nov 15 '12 at 21:51
  • removed the abc.inc and copied to unit2.pas. I am able to ctrl+left mouse button on 'Interface_info' and it will navigate to unit2 where Interface_info is declared. Still same problem. same error. :( – Nalu Nov 15 '12 at 21:53
  • 1
    @jachguate, we can only guess, most likely the code is not real code. – LU RD Nov 15 '12 at 21:53
  • the code working good in Delphi 5. – Nalu Nov 15 '12 at 22:00
  • 2
    ULONG is declared in winApi.windows. I don't see any reference to this unit in your code. There is not any interface/implementation declaration either. Please, show real code. – LU RD Nov 15 '12 at 22:04
  • @Naren, not the code you published here, tough. – jachguate Nov 15 '12 at 22:05
  • @RemyLebeau: Please point out where I said it was invalid, if you would. I certainly can't see it. I suggested combining them into a single unit so that the problem could be easily determined, and I posted a comment rather than an answer because it was just that - a suggestion. As far as `WinAPI`, you're correct; I misread it as being the old Delphi 1 compatibility **unit** alias. – Ken White Nov 15 '12 at 22:41
  • @KenWhite: yes, your misreading of `WinAPI` is what I was referring to. Yes, removing the `WinAPI` **unit** would be correct, but removing the `Winapi` **unit scope** is not. – Remy Lebeau Nov 16 '12 at 00:20
  • @RemyLebeau: That was your second comment. The first is the one I was questioning: "It is perfect valid to continue using an .inc file.". As I said, your second comment was correct - I misread the error related to `WinAPI`. – Ken White Nov 16 '12 at 00:23

1 Answers1

1

As commented, your code can't be real code.

I'm posting this, which I compiled right now with Delphi XE3 without any problem.

file: abc.inc

type
  Interace_Info = packed record
    iflag: ulong;
  end;

file: Unit2.pas

unit Unit2;

interface
uses winapi.Windows;

{$include abc.inc}

implementation

end.

file: Unit1.pas

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)
    Button1: TButton;
    procedure Button1Click(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  Form1: TForm1;

implementation
uses Unit2;

type
  TLocal = array[0..10] of Interace_Info;

{$R *.dfm}

procedure TForm1.Button1Click(Sender: TObject);
var
  ALocal: TLocal;
begin
  ALocal[0].iflag := 0;
  ShowMessage(IntToStr(ALocal[0].iflag));
end;

end.

It compiles and run without any problem.

jachguate
  • 16,976
  • 3
  • 57
  • 98
  • ulong: Dword is declared in unit2.pas. can not copy the code as it is as the code is on remote machine. Sorry for that. – Nalu Nov 15 '12 at 22:33
  • thanks for answer but the application is compiling without any error on delphi 5 also. I am not getting where is exact error. When I press ctrl+let mouse button rom Interace_info its redirecting to crrect location. And error saying Undeclared Identifier. Is it possible that due to other any file reerence its happening? – Nalu Nov 15 '12 at 22:43
  • Naren, it's hard to say... you have to try to aisle the correct problem before posting random questions, since you're the only one who have access to the source code and don't want (or can't) post the real code. I have no idea what your project looks like to make a informed guess about what could be happening. – jachguate Nov 15 '12 at 22:49