Solved

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

Posted on 1998-09-20
6
129 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
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.

 
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

Highfive + Dolby Voice = No More Audio Complaints!

Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

Join & Write a Comment

Have you ever had your Delphi form/application just hanging while waiting for data to load? This is the article to read if you want to learn some things about adding threads for data loading in the background. First, I'll setup a general applica…
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…
Illustrator's Shape Builder tool will let you combine shapes visually and interactively. This video shows the Mac version, but the tool works the same way in Windows. To follow along with this video, you can draw your own shapes or download the file…
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…

758 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

19 Experts available now in Live!

Get 1:1 Help Now