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
Solved

Conditional use

Posted on 2002-07-03
9
147 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
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
Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

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

 
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: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

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

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…
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…
A short tutorial showing how to set up an email signature in Outlook on the Web (previously known as OWA). For free email signatures designs, visit https://www.mail-signatures.com/articles/signature-templates/?sts=6651 If you want to manage em…

828 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