Watch, Follow, &
Connect with Us

For forums, blogs and more please visit our
Developer Tools Community.


Welcome, Guest
Guest Settings
Help

Thread: Getting the wrong unit.h file



Permlink Replies: 4 - Last Post: May 24, 2017 9:48 AM Last Post By: Alex Belo Threads: [ Previous | Next ]
Asger Joergensen

Posts: 370
Registered: 11/18/08
Getting the wrong unit.h file
Click to report abuse...   Click to reply to this thread Reply
  Posted: May 23, 2017 9:14 AM
Hi

I have a rather large project where I have "outsourced" three units
to another much smaller project, so they are easier to work on.

One of these units(a thread) call/syncronize a function in unit1,
in order to show errors, I therefor include unit1.h.
In the Alt F11 dialog, Unit1.h is shown with the correct path, to
the small project, but when I compile I get an error saying that
the function I'm calling isn't a member of TForm1.

If i put the cursor in unit1.h and hit Ctrl+Enter, the unit1.h from
my large project is the one that is opening, the unit1.h that is in
the same directory as the three "outsourced" units, but NOT part of
the project I'm working in.

This is a bug, right ?

If so is it known ?

Thanks in advance
Best regards
Asger
Remy Lebeau (Te...


Posts: 9,447
Registered: 12/23/01
Re: Getting the wrong unit.h file
Click to report abuse...   Click to reply to this thread Reply
  Posted: May 23, 2017 10:05 AM   in response to: Asger Joergensen in response to: Asger Joergensen
Asger Joergensen wrote:

One of these units(a thread) call/syncronize a function in unit1,
in order to show errors, I therefor include unit1.h.

A better design is to have the thread unit define an event callback
that the thread calls if assigned. And then Unit1 (or any other unit)
can assign a handler to that event when creating instances of the
thread. This way, the thread unit does not need to know anything about
Unit1 at all, and there is no dependancy issues while compiling the
thread unit.

In the Alt F11 dialog, Unit1.h is shown with the correct path, to
the small project, but when I compile I get an error saying that
the function I'm calling isn't a member of TForm1.

If i put the cursor in unit1.h and hit Ctrl+Enter, the unit1.h from
my large project is the one that is opening, the unit1.h that is in
the same directory as the three "outsourced" units, but NOT part of
the project I'm working in.

That likely means you have multiple versions of Unit1.h on your
machine, and the compiler is finding a different version than you are
expecting. Check your includes paths, or get rid of the duplicates.

This is a bug, right ?

No.

--
Remy Lebeau (TeamB)
Alex Belo

Posts: 626
Registered: 10/8/06
Re: Getting the wrong unit.h file
Click to report abuse...   Click to reply to this thread Reply
  Posted: May 23, 2017 10:25 AM   in response to: Remy Lebeau (Te... in response to: Remy Lebeau (Te...
Remy Lebeau (TeamB) wrote:

Check your includes paths

Sometimes order of paths matters.

--
Alex
Alex Belo

Posts: 626
Registered: 10/8/06
Re: Getting the wrong unit.h file
Click to report abuse...   Click to reply to this thread Reply
  Posted: May 24, 2017 9:48 AM   in response to: Alex Belo in response to: Alex Belo
Alex Belo wrote:

Sometimes order of paths matters.

I recall my case like this.

I had 2 units in one directory, say Unit1 and Unit2, in project.

One day I decided to add some functionality to Unit2. I copied Unit2
into another directory, removed old unit2 from project and added new
Unit2 to the project.

After some editing of actual Unit2.h compilation of the project which
uses it in other units failed.

Reason: Unit1.h is still in project and path to directory with Unit1
and old Unit2.h is situated before path to new Unit2.

--
Alex
Asger Joergensen

Posts: 370
Registered: 11/18/08
Re: Getting the wrong unit.h file
Click to report abuse...   Click to reply to this thread Reply
  Posted: May 24, 2017 1:00 AM   in response to: Remy Lebeau (Te... in response to: Remy Lebeau (Te...
Hi Remy

Remy Lebeau (TeamB) wrote:

Asger Joergensen wrote:

One of these units(a thread) call/syncronize a function in unit1,
in order to show errors, I therefor include unit1.h.

A better design is to have the thread unit define an event callback
that the thread calls if assigned. And then Unit1 (or any other unit)
can assign a handler to that event when creating instances of the
thread. This way, the thread unit does not need to know anything about
Unit1 at all, and there is no dependancy issues while compiling the
thread unit.

Thanks I'll do that instead.

Best regards
Asger
Legend
Helpful Answer (5 pts)
Correct Answer (10 pts)

Server Response from: ETNAJIVE02