Solved

Conditional use

Posted on 2002-07-03
9
148 Views
Last Modified: 2011-10-03
Hi,

I have a flag in the registry called "ShowOptions" that can be "YES" or "NO". In the Main.pas unit of my project, I want to load (or use) another unit called "UOptions.pas" depending of the value in the the registry. I want that because the unit "UOptions.pas" refers to some DLL and these files are not necessarly on the client machine.

How can I do that ????
0
Comment
Question by:roioep
[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
9 Comments
 
LVL 8

Expert Comment

by:TOndrej
ID: 7127666
Instead of linking to the DLLs statically (function ... external ...), you should load the DLL dynamically at runtime, using LoadLibrary, GetProcAddress, FreeLibrary.
0
 

Author Comment

by:roioep
ID: 7127779
"UOptions" is a frame with controls. The form "UMain.pas" contains the UOptions frame. This frame use a lot of dll. I don't want to "use" the frame if the registry key says "NO".
0
 

Author Comment

by:roioep
ID: 7127790
What I want is to be able to use or not a unit and its components at runtime...
0
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 8

Expert Comment

by:TOndrej
ID: 7127817
Let's clarify one point: You don't want to use the frame because the DLLs used by the frame may not be present on the target system.
So your real problem is the DLLs, not the frame.

The only way to conditionaly use a unit is to compile it into a runtime package which would be loaded or not dynamically at runtime. This may introduce you to a whole new set of problems, especially if you haven't done it before.

Why not attack the root of the problem? Redesign the frame unit so that it does not link the DLLs statically but loads them dynamically at runtime...
Just my 2c, of course.
0
 
LVL 14

Expert Comment

by:DragonSlayer
ID: 7129217
TOndrej, you always say it's only your 2c, but you always give very useful 2c... :)
0
 
LVL 34

Expert Comment

by:Slick812
ID: 7130935
hello roloep, I may not compleatly understand your problem, but it seems like you do not want the Frame to be present if the boolean is False in the registry. Since a Frame is like a Form you might try this, click on the frame and then click "Delete" in the Edit menu, to remove it from your main form. You can look in the Project Menu "Options" an see on the 'Forms" Tab that the Main Form "Form1" is in "Auto-Create" side and the "Frame1" is on the "Availible" forms side. Now in your Main Forms OnCreate Event add this code

procedure TForm1.FormCreate(Sender: TObject);
begin
{get the ShowOptions value}
if ShowOptions then
  begin
  Application.CreateForm(TFrame1, UOptions);
  UOptions.Parent := Self;
  UOptions.Visible := True;
  UOptions.Top := 88;
  UOptions.Left := 488;
  //UOptions.Color := clRed;
  {add any start up code here}
  end;
end;

this will load your Form without the Frame if ShowOptions is False and the UOptions.pas won't be executed
0
 

Expert Comment

by:CleanupPing
ID: 9343112
roioep:
This old question needs to be finalized -- accept an answer, split points, or get a refund.  For information on your options, please click here-> http:/help/closing.jsp#1 
EXPERTS:
Post your closing recommendations!  No comment means you don't care.
0
 
LVL 5

Expert Comment

by:Lukasz Lach
ID: 9460048
roioep,
No comment has been added lately (18 days), so it's time to clean up this TA.
I will leave a recommendation in the Cleanup topic area for this question:

RECOMMENDATION: PAQ/No Refund

Please leave any comments here within 7 days.

-- Please DO NOT accept this comment as an answer ! --

Thanks,

anAKiN
EE Cleanup Volunteer
0
 

Accepted Solution

by:
YensidMod earned 0 total points
ID: 9534299
This question is PAQed and no points refunded (of 50)

YensidMod
Community Support Moderator
0

Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying 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

Creating an auto free TStringList The TStringList is a basic and frequently used object in Delphi. On many occasions, you may want to create a temporary list, process some items in the list and be done with the list. In such cases, you have to…
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…
The Email Laundry PDF encryption service allows companies to send confidential encrypted  emails to anybody. The PDF document can also contain attachments that are embedded in the encrypted PDF. The password is randomly generated by The Email Laundr…

730 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