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?
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
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
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.