Watch, Follow, &
Connect with Us

For forums, blogs and more please visit our
Developer Tools Community.


Welcome, Guest
Guest Settings
Help

Thread: Forms and conditional compilation


This question is answered.


Permlink Replies: 3 - Last Post: Oct 25, 2014 7:59 AM Last Post By: Wayne Niddery
Mark Gorst

Posts: 23
Registered: 6/7/02
Forms and conditional compilation  
Click to report abuse...   Click to reply to this thread Reply
  Posted: Oct 21, 2014 1:34 AM
I've got an application that interfaces to a hardware device, but the device may come from one
of a number of different manufacturers, and so we build an EXE to customise to each of the devices.

This is done with conditional compiles. There are two areas where we need this, where we have
a derived class to handle the device, and where we have a derived form for each device.

So if we have three devices A,B,C we have three configurations with conditional compiles DEVICEA,
DEVICEB, DEVICEC.

This works fine for the derived classes TDeviceA, TDeviceB, TDeviceC, derived from TDevice.

The problem is in the form. So we have TFormDevice, but we want to then have TFormDeviceA, TFormDeviceB, TFormDeviceC.

The way we currently have this configured is to have {$IFDEF DEVICEA}....{$ENDIF} around the contents of the interface and implementation blocks. This works fine in terms of compilation.

The problem we have is this excludes the {$ *.DFM} and so what happens is that the IDE no longer gives access to the DFM. So we can't get into design mode (F12). Presumably this is because the IDE is not aware that the directive is "active" in the current configuration.

So if I select configuration to build for DEVICEA then the source for TFormDeviceA compiles, but I can't access the TFormDeviceA DFM through the IDE.

I have a workround, but I was wondering if I'm missing a better way of organising the conditional directives, so that the DFM is recognised in the IDE when the Build Configuration is selected.

I've scratched my head a lot, but not spotted it yet. All suggestions greatfully received.
Peter Below

Posts: 1,227
Registered: 12/16/99
Re: Forms and conditional compilation
Correct
Click to report abuse...   Click to reply to this thread Reply
  Posted: Oct 21, 2014 10:30 AM   in response to: Mark Gorst in response to: Mark Gorst
Mark Gorst wrote:

I've got an application that interfaces to a hardware device, but the
device may come from one of a number of different manufacturers, and
so we build an EXE to customise to each of the devices.

This is done with conditional compiles. There are two areas where we
need this, where we have a derived class to handle the device, and
where we have a derived form for each device.

So if we have three devices A,B,C we have three configurations with
conditional compiles DEVICEA, DEVICEB, DEVICEC.

This works fine for the derived classes TDeviceA, TDeviceB, TDeviceC,
derived from TDevice.

The problem is in the form. So we have TFormDevice, but we want to
then have TFormDeviceA, TFormDeviceB, TFormDeviceC.

The way we currently have this configured is to have {$IFDEF
DEVICEA}....{$ENDIF} around the contents of the interface and
implementation blocks. This works fine in terms of compilation.

The problem we have is this excludes the {$ *.DFM} and so what
happens is that the IDE no longer gives access to the DFM. So we
can't get into design mode (F12). Presumably this is because the IDE
is not aware that the directive is "active" in the current
configuration.

So if I select configuration to build for DEVICEA then the source for
TFormDeviceA compiles, but I can't access the TFormDeviceA DFM
through the IDE.

I have a workround, but I was wondering if I'm missing a better way
of organising the conditional directives, so that the DFM is
recognised in the IDE when the Build Configuration is selected.

No, conditional compilation and the form designer do not work together.
What you need to do is to create a base form class with stuff common to
all devices, and add a method you call from the designer that creates
the device-specific things in code. You can use conditional compilation
inside the form code, as long as you don't touch the designer-managed
part of the form class declaration.

If the visual stuff that is device-dependent is not too complex it is
no big problem to create it in code.

Another option that will work if you build your project with run-time
packages anyway is to externalize the device-depend parts of the UI (as
frames) to packages, one package per device. You can then let your form
load the required package at run-time and call a method exported by the
package to get an instance of the frame to parent to the placeholder
panel (or whatever you use) on the host application's form.

How simple or complex that is depends on the amount of communication
you need between the device-dependent frame and its host form.

--
Peter Below (TeamB)
Mark Gorst

Posts: 23
Registered: 6/7/02
Re: Forms and conditional compilation  
Click to report abuse...   Click to reply to this thread Reply
  Posted: Oct 22, 2014 3:53 AM   in response to: Peter Below in response to: Peter Below
Thanks. At least I know it won't work and there are now a number of strategies to persue.

Just FYI the workround we have at the moment is simply to comment out the conditionals if you need access to the Form Designer - bodgy, but it works.

Thanks again for swift reply

Mark
Wayne Niddery

Posts: 791
Registered: 4/14/98
Re: Forms and conditional compilation  
Click to report abuse...   Click to reply to this thread Reply
  Posted: Oct 25, 2014 7:59 AM   in response to: Mark Gorst in response to: Mark Gorst
"Mark Gorst" wrote in message news:698367 at forums dot embarcadero dot com...

The problem we have is this excludes the {$ *.DFM} and so what happens is
that the IDE no longer gives access to the DFM. So we can't get into
design mode (F12). Presumably this is because the IDE is not aware that
the directive is "active" in the current configuration.

So if I select configuration to build for DEVICEA then the source for
TFormDeviceA compiles, but I can't access the TFormDeviceA DFM through the
IDE.

I have a workround, but I was wondering if I'm missing a better way of
organising the conditional directives, so that the DFM is recognised in
the IDE when the Build Configuration is selected.

Another suggestion is that this form simply be a host. Design the
device-specific forms free of conditional compiles, but which form gets
created at run time is controlled by the conditionals and that form is then
embedded into the host form. This can also be done with frames though I
personally prefer child forms over frames. The device-specfic forms merely
turn off all header/border properties so it simply becomes a child control
on the host form.

--
Wayne Niddery
"You know what they call alternative medicine that has been proven to work?
Medicine." - Tim Minchin

Legend
Helpful Answer (5 pts)
Correct Answer (10 pts)

Server Response from: ETNAJIVE02