Solved

Conditional use

Posted on 2002-07-03
9
144 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
Comment Utility
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
Comment Utility
"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
Comment Utility
What I want is to be able to use or not a unit and its components at runtime...
0
 
LVL 8

Expert Comment

by:TOndrej
Comment Utility
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
What Is Threat Intelligence?

Threat intelligence is often discussed, but rarely understood. Starting with a precise definition, along with clear business goals, is essential.

 
LVL 14

Expert Comment

by:DragonSlayer
Comment Utility
TOndrej, you always say it's only your 2c, but you always give very useful 2c... :)
0
 
LVL 33

Expert Comment

by:Slick812
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
This question is PAQed and no points refunded (of 50)

YensidMod
Community Support Moderator
0

Featured Post

Better Security Awareness With Threat Intelligence

See how one of the leading financial services organizations uses Recorded Future as part of a holistic threat intelligence program to promote security awareness and proactively and efficiently identify threats.

Join & Write a Comment

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 my programming career I have only very rarely run into situations where operator overloading would be of any use in my work.  Normally those situations involved math with either overly large numbers (hundreds of thousands of digits or accuracy re…
It is a freely distributed piece of software for such tasks as photo retouching, image composition and image authoring. It works on many operating systems, in many languages.
You have products, that come in variants and want to set different prices for them? Watch this micro tutorial that describes how to configure prices for Magento super attributes. Assigning simple products to configurable: We assigned simple products…

771 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

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now