Common for for multiple apps

What is best option in below scenario
I have two Delphi apps app1 and app2, they have their own data modules say dm1 and dm2 respectively.
Now I actually was running app2 from app1 hence there was no issue in accessing an query component placed in dm1 from a common frame being used by both apps.
Now I need to run app2 as standalone and it throws exception at a line where it sees the reference to query component of dm1.

So I have used ifdef conditional directives but is there any other solution?
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Geert GOracle dbaCommented:
use of ifdef will complicate things
and it's not good in this case

are app1 and app2 full exe's ?
or is 1 a dll ?
AbhiJeetAuthor Commented:
Yes both are exes
In uses section I am using as
{ifdef app1}dm1, {endif} {ifdef app2}dm2,{endif}

And then accessing the query component with same directives as
{ifdef app1}
With dm1.query1 do
{ifdef app2}
With dm2.query1 do
// do whatever

But yeah this may become difficult with this approach in code manageability hence what alternate way I can code?
AbhiJeetAuthor Commented:
Any alternate option is available or I should go ahead with the coding I have done
Geert GOracle dbaCommented:
a remark:
do not use compiler directives
unless it's to make it compatible across multiple delphi versions

i started programming delphi at a company where they had 5 apps use multiple common units

each app had a directive
define APP1

the common unit was a regular nightmare.
From my memory :
function CalcHours(Ds: TDataset): double;
    Result := 0;
  result := 0;
  while not ds.Eof do 
    Result := Result + (ds.FieldByName('DT_END').AsDateTime - ds.FieldByName('DT_START').AsDateTime)*24;
    if Result > 8 then Result := 8;

Open in new window


the nightmare was not only finding the bugs.

the real problem was having 2 delphi's open with APP1 in the first Delphi and App2 in the second Delphi
Was sometimes easy with multiple monitors to work on same functionality with 2 delphi's
Everytime you change code, the syntax helper kicks in
This requires compiled units, with matching IFDEF declarations
So when you change code of APP1 ... it needs to recompile all it's units with APP1 definer.
takes a while ...

And when you'd change code in APP2, it notes the units are compiled with APP1
and has to recompile them ...
so you are introducing a very annoying feature

just to let you know

and i'll repeat my remark :
do not use compiler directives
unless it's to make it compatible across multiple delphi versions

with code samples, i could probably fix your issues ...
you probably have circular unit references too

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today

From novice to tech pro — start learning today.