Go Premium for a chance to win a PS4. Enter to Win

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 219
  • Last Modified:

Conditional compile


Is it possible to use conditional compiling in DFM files (somehow, sice {$IFDEF} doesn't work)?

I need to disable some components like this:
(this is: "View form as a text" source of DFM)

{$ifdef DEMO}
  object Timer1: TTimer
    Interval = 100
    OnTimer = Timer1Timer
    Top = 528
  end
{$ENDIF}
0
yuhoo
Asked:
yuhoo
1 Solution
 
JaccoCommented:
Not possible according to me.

You can disable it programmatically.

Or you can make two forms and make your uses claus contitional:
uses
{$IFDEF DEMO}
  unit1,
{$ELSE}
  unit2,
{$ENDIF}
0
 
LischkeCommented:
This is not possible at all. What you can do is to specify something like:

{$ifdef ver100}
  {$r D3.dfm}
{$else}
  {$r D2.dfm
{$endif}

and it will compile, but this way you cannot open the formular in the IDE.

So the answer is no.

Ciao, Mike
0
 
rickpetCommented:
You can't do this in the dfm...but why do you need to...

you can do this in the pas file...and create it dynamically...

{$ifdef DEMO}
  Timer1 := TTimer.Create(self);
  with Timer1 do
  begin
    Interval := 100;
    OnTimer := Form1Timer;
    Top := 528;
  end;
{$ENDIF}

remember to wrap calls to Timer1 in nil checks...i.e. if Assigned(Timer1) then or if Timer1 <> nil then...

Rick
0
 
yuhooAuthor Commented:
What would you do if you wanted to make multi language application with lot of Labels on a Form?
0

Featured Post

Important Lessons on Recovering from Petya

In their most recent webinar, Skyport Systems explores ways to isolate and protect critical databases to keep the core of your company safe from harm.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now