Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

how to use $IF ? 1

Status
Not open for further replies.

shmilyca

Programmer
Apr 30, 2006
63
US
Hi,
I have application level global variable called OpenFormType(string). I want to execute following procedure only if OpenFormType='1'

procedure TForm1.CreateParams(var Params: TCreateParams);
begin
inherited CreateParams(Params);
with Params do
Style := Style or ws_Border or ws_ThickFrame;
end;

How do I do that? Please help.

Thank you.
 
$IF is a compiler directive. This means it takes effect when your source code is being compiled.

At compile time, the compiler does not know whether your string variable OpenFormType will contain the value '1' or not at run time.

So you need to test OpenFormType at run time. This is typically done with an if statement:
Code:
  if OpenFormType = '1' then
    CreateParams( params );
Alternatively, you might consider
Code:
procedure TForm1.CreateParams(var Params: TCreateParams);
begin
   inherited CreateParams(Params);
   if OpenFormType = '1' then
      with Params do
         Style := Style or ws_Border or ws_ThickFrame;
end;
if it is necessary to call the inherited procedure.

The use of application global variables should be minimised where possible.

Andrew
Hampshire, UK
 
Thanks Andrew for your help. I appriciate it.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top