Solved

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

Posted on 1998-09-20
6
133 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
  • 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
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
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 50 total points
ID: 1340347
Glad to be able to help.

/// John
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

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…
Introduction Raise your hands if you were as upset with FireMonkey as I was when I discovered that there was no TListview.  I use TListView in almost all of my applications I've written, and I was not going to compromise by resorting to TStringGrid…
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…

730 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