Common for for multiple apps

Experts
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?
AbhiJeetAsked:
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;
begin
  {$IFDEF APP1}
  {$IFDEF APP2}
    Result := 0;
  {$ENDIF}
  {$ENDIF}
  {$IFDEF APP3}{$IFDEF APP4}
  result := 0;
  ds.First;
  while not ds.Eof do 
  begin
    Result := Result + (ds.FieldByName('DT_END').AsDateTime - ds.FieldByName('DT_START').AsDateTime)*24;
    ds.Next;
  end;
  {$ENDIF}{$ENDIF}
  {$IFDEF APP4}
    if Result > 8 then Result := 8;
  {$ENDIF}
end;

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
0
 
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 ?
0
 
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
{endif}
{ifdef app2}
With dm2.query1 do
{endif}
Begin
// do whatever
End

But yeah this may become difficult with this approach in code manageability hence what alternate way I can code?
0
 
AbhiJeetAuthor Commented:
Any alternate option is available or I should go ahead with the coding I have done
0
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.