Solved

Conditional use

Posted on 2002-07-03
9
145 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
 
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
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
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 33

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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
ddeman not working in activex 3 93
proper way to parse text with delphi 7 101
Mobile Keyboard covers the display of the TMemo 3 78
Find and Replace Stream with 0s 8 57
Introduction The parallel port is a very commonly known port, it was widely used to connect a printer to the PC, if you look at the back of your computer, for those who don't have newer computers, there will be a port with 25 pins and a small print…
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…
Internet Business Fax to Email Made Easy - With eFax Corporate (http://www.enterprise.efax.com), you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, fr…
Hi friends,  in this video  I'll show you how new windows 10 user can learn the using of windows 10. Thank you.

895 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

13 Experts available now in Live!

Get 1:1 Help Now