Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Where do I put functions and procedures I want to run at startup?

Posted on 1998-09-20
6
Medium Priority
?
136 Views
Last Modified: 2010-04-06
Based on command line options I've set my main form to Application.ShowMainForm := False; in the OnCreate event. I now want to process the command line and access functions and procdures that are in the project without showing the main form. I tried to access these functions and procedures from within the OnCreate Event but I get access violations. I assume the errors are because program hasn't fully loaded. Where do I call these functions and procdures from? I tried OnActivate, but it only gets called when the mainform is not hidden.

Thanks
0
Comment
Question by:ripcord
[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
  • 3
  • 3
6 Comments
 
LVL 4

Expert Comment

by:erajoj
ID: 1340342
Hi,
What procedures/functions?
If the procedures/functions you're talking about are in standalone units then make sure you have included them in your project source file's (*.dpr) uses statement and then simply do all the processing there.

Example:

Project source:

program Project1;

uses
  Forms,
  Unit1 in 'Unit1.pas' {Form1},
  MyUnit in 'MyUnit.pas'; // here's your unit!
{$R *.RES}

begin
  Application.ShowMainForm := False;
  Application.Initialize;
  Application.CreateForm(TForm1, Form1);
  if ( MyUnit.CheckParameters ) then
  begin
    Application.ShowMainForm := True;
  end;
  Application.Run;
end.

Standalone unit:

unit MyUnit;

interface

function CheckParameters: Boolean;

implementation

uses
  SysUtils;

function CheckParameters: Boolean;
begin
  Result := CompareText( ParamStr( 1 ), '/hidden' ) <> 0
end;

end.

Explain further...!

/// John
0
 

Author Comment

by:ripcord
ID: 1340343
I am calling functions and procedures from both the main form(unit) and standalone forms(units). They are the same functions and procdures I normally call when the form is not hidden, so all the units are in my uses statement. It looks like I get the error when one of the procdures attemts to close the application using Close; Is this not allowed from within the OnCreate event or should I be closing in another way?
0
 

Author Comment

by:ripcord
ID: 1340344
Also when calling a procedure from OnCreate that tries to access ParamCount, the value for ParamCount says "inacessable value".
0
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

 
LVL 4

Expert Comment

by:erajoj
ID: 1340345
Hi,
Use Halt. Close is not available in the OnCreate event.
The reason you can't see ParamCount when debugging is simply because it is a function and not an integer value. It still works (I have tested it).
Sometimes when you get "inacessable value" while debugging is because the awesome object pascal compiler has optimized it out since there is no need for that value at the moment.

procedure TForm1.FormCreate(Sender: TObject);
var
  cParam: Integer;
begin
  cParam := ParamCount;
  Caption := IntToStr( cParam );
  if ( MyUnit.CheckParameters ) then
  begin
    Application.ShowMainForm := True;
  end else
  begin
    Halt;
  end;
end;



0
 

Author Comment

by:ripcord
ID: 1340346
thanks, it's all working now. Please answer the question to get credit.
0
 
LVL 4

Accepted Solution

by:
erajoj earned 200 total points
ID: 1340347
Glad to be able to help.

/// John
0

Featured Post

[Webinar] Lessons on Recovering from Petya

Skyport is working hard to help customers recover from recent attacks, like the Petya worm. This work has brought to light some important lessons. New malware attacks like this can take down your entire environment. Learn from others mistakes on how to prevent Petya like worms.

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…
This course is ideal for IT System Administrators working with VMware vSphere and its associated products in their company infrastructure. This course teaches you how to install and maintain this virtualization technology to store data, prevent vuln…
In this video, Percona Director of Solution Engineering Jon Tobin discusses the function and features of Percona Server for MongoDB. How Percona can help Percona can help you determine if Percona Server for MongoDB is the right solution for …
Suggested Courses

636 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