Solved

Conditional Compile in Run-Time Package

Posted on 1998-07-14
5
320 Views
Last Modified: 2010-04-04
The Delphi 3 help file has a section that briefly mentions a Conditionals tab in the Packages Option Dialog. Obviously, there's not one there. So how do I put conditionally compiled code into a unit that's compiled into a run-time package?
0
Comment
Question by:chrismo
  • 3
5 Comments
 
LVL 12

Accepted Solution

by:
rwilson032697 earned 100 total points
Comment Utility
chrismo,

Delphi does not give you much control over compiling packages from the IDE. However, there are ways to get around it.

1. If you need to set specific compiler directives for your code then these can be set in the code itself.

2. For conditional compilation the only real work-around you have (at least in v3, I'm not sure about v4) is to have an include file which contains the necessary defines....

eg: MyDefines.Inc
{$DEFINE MYDEFINE1}
{$DEFINE MYDEFINE2}

This can then include this at the top of your unit(s) like this:

{$I MyDefines.Inc}

Does this help?
0
 

Author Comment

by:chrismo
Comment Utility
So I'd have to have two different include files and manually switch them to do my builds?
0
 
LVL 1

Expert Comment

by:Edo082297
Comment Utility
Hello

We have an application that is broken into many run-time packages, and all of the units contain conditional compilation because the application must be bilingual. When you include a unit that contains conditional compilation, each time you do a build all Delphi will include only what is called and used, right down to the statement level due to the magic of the smart linker. So, when you do a final build, you will create a version that will depend on what switches you have set.
Why does this pose a problem?

Edo
0
 

Author Comment

by:chrismo
Comment Utility
I'd forgotten to include my original problem in the first post:

I only have one section of a unit in a run-time pkg right now that has a conditional compile

{$IFDEF Alpha}
// blah blah blah
{$ENDIF}

If the main .dpr includes the Alpha directive -- everything works fine.

If the main .dpr does *not* include the Alpha directive -- the code in the run-time package acts unpredictably. Stepping through the code yields random results (jumps from one method to the middle of another method not even being called -- very bizarre behavior). I put the Alpha directive back in, and everything works fine again.

Oh, and yes, I make sure and rebuild the .dpl after I switch the directive. Should Delphi be rebuilding the .dpl itself when I do a Build All? -- because it doesn't. I do have the package option Rebuild As Needed set.

Wait ... I take that back - Delphi is rebuilding the .dpl when I do a Build All. But this doesn't help.

I do a Build All with Alpha - then step through the code in the run-time unit, everything's fine.

I do a Build All without Alpha - then step through the code in the run-time unit, and I get random stepping behavior. Sometimes the code appears to execute correctly anyway, many times the code doesn't run properly.

The method that contains the conditional compile section is not even executed by the portion I'm stepping through. It's weird.
0
 

Author Comment

by:chrismo
Comment Utility
Well ... here's the full deal. I've 'fixed' it. Following is the original code:

procedure TTIMObject.LogChanges;
var
  i: integer;
  thisFieldLink: TFieldLink;

  function GetNextTransID: integer;
  begin
    with TIMDM.qryGetNextID do begin
      Prepare;
      ParamByName('strTableName').AsString := 'tblTransaction';
      Open;
      Result := FieldByName('intNextID').AsInteger;
      Close;
    end;

    with TIMDM.qrySetNextID do begin
      Prepare;
      ParamByName('strTableName').AsString := 'tblTransaction';
      ParamByName('intNextID').AsInteger := Result + 1;
      ExecSQL;
      Close;
    end;
  end;
begin
{$IFDEF OFFICE}
  if FLogChanges then begin
    for i := 0 to FFieldLinks.Count - 1 do begin
      thisFieldLink := TFieldLink(FFieldLinks[i]);
      with thisFieldLink do begin
        if Modified then begin
          with TIMDM.qryInsertTransaction do begin
            Prepare;
            ParamByName('cntTransID').AsInteger := GetNextTransID;
            ParamByName('intTransType').AsInteger := 1;
            ParamByName('intColumnID').AsInteger := DBFieldID;
            ParamByName('intObjectID').AsInteger := FID;
            ParamByName('strOldValue').AsString := OldValue;
            ParamByName('strNewValue').AsString := NewValue;
            ParamByName('dtmDateTime').AsDateTime := FTimeStamp;
            ParamByName('intUserID').AsInteger := FUserID;
            ExecSQL;
            Close;
          end;
          Modified := false;
        end;
      end;
    end;
  end;
{$ENDIF}  
  FLogged := true;
end; { LogChanges }

If I compiled with the OFFICE directive ... everything worked fine. If I compiled without the OFFICE directive - stepping into code acted very strange. Keep in mind the above method was not involved at all.

I decided on a whim to remove the GetNextTransID local method and make it a protected method of the object.

Making that changed fixed my glitch. I have no idea why. Now, no matter how I conditionally compile, stepping through the code works just fine. Very bizarre.
0

Featured Post

What Security Threats Are You Missing?

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

The uses clause is one of those things that just tends to grow and grow. Most of the time this is in the main form, as it's from this form that all others are called. If you have a big application (including many forms), the uses clause in the in…
Introduction I have seen many questions in this Delphi topic area where queries in threads are needed or suggested. I know bumped into a similar need. This article will address some of the concepts when dealing with a multithreaded delphi database…
This video gives you a great overview about bandwidth monitoring with SNMP and WMI with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're looking for how to monitor bandwidth using netflow or packet s…
When you create an app prototype with Adobe XD, you can insert system screens -- sharing or Control Center, for example -- with just a few clicks. This video shows you how. You can take the full course on Experts Exchange at http://bit.ly/XDcourse.

728 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

9 Experts available now in Live!

Get 1:1 Help Now