Solved

Conditional Compile in Run-Time Package

Posted on 1998-07-14
5
328 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
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

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

A lot of questions regard threads in Delphi.   One of the more specific questions is how to show progress of the thread.   Updating a progressbar from inside a thread is a mistake. A solution to this would be to send a synchronized message to the…
In this tutorial I will show you how to use the Windows Speech API in Delphi. I will only cover basic functions such as text to speech and controlling the speed of the speech. SAPI Installation First you need to install the SAPI type library, th…
Email security requires an ever evolving service that stays up to date with counter-evolving threats. The Email Laundry perform Research and Development to ensure their email security service evolves faster than cyber criminals. We apply our Threat…
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …

809 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