?
Solved

Conditional Compile in Run-Time Package

Posted on 1998-07-14
5
Medium Priority
?
340 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
5 Comments
 
LVL 12

Accepted Solution

by:
rwilson032697 earned 100 total points
ID: 1357895
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
ID: 1357896
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
ID: 1357897
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
ID: 1357898
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
ID: 1357899
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

Want to be a Web Developer? Get Certified Today!

Enroll in the Certified Web Development Professional course package to learn HTML, Javascript, and PHP. Build a solid foundation to work toward your dream job!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Hello everybody This Article will show you how to validate number with TEdit control, What's the TEdit control? TEdit is a standard Windows edit control on a form, it allows to user to write, read and copy/paste single line of text. Usua…
Introduction Raise your hands if you were as upset with FireMonkey as I was when I discovered that there was no TListview.  I use TListView in almost all of my applications I've written, and I was not going to compromise by resorting to TStringGrid…
If you’ve ever visited a web page and noticed a cool font that you really liked the look of, but couldn’t figure out which font it was so that you could use it for your own work, then this video is for you! In this Micro Tutorial, you'll learn yo…
In this video, Percona Solutions Engineer Barrett Chambers discusses some of the basic syntax differences between MySQL and MongoDB. To learn more check out our webinar on MongoDB administration for MySQL DBA: https://www.percona.com/resources/we…
Suggested Courses
Course of the Month9 days, 19 hours left to enroll

762 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