How to program a small delphi application?

Hi all,
  I found that the application compiled from delphi is so big ! Even I havent add any thing to the form , the app after complied is also 300K above , in fact ,some times I neednt use GUI to do my job ,how can I remove the form and just compile the part that has the function I want ?

Regards,
Sam
Sam80Asked:
Who is Participating?
 
Slick812Connect With a Mentor Commented:
I am not sure what to post here for you, you seem to talk about the console application, and you say you do not want any GUI? ? You also say you used a console and then asked

" In console application , I want to hold my application for several minutes, not terminated as it run to the last code. how to do i"

consoles were not meant to last beyond the final text read or write. . . .

anyway, here is some code you might can look at, but you may not be able to use it (you may not know what it is doing)


first code for your  .DPR   program file - -


program Conect;

uses
  MakeConect;

begin
if Startup then
  RunMsgLoop;
end.



 = = = = = = = = = =  = = = =  = = =

next id the code for the MakeConect  Unit - -




unit MakeConect;

interface

function StartUp: Boolean;

procedure RunMsgLoop;

implementation

uses Windows, Messages;

type
{if you need to Assign Object Events like OnClick, OnReceive, then
you will need to Have a TObject with the Event Methods in it,
like this TOzObject}
  TOzObject = Class(TObject)
  private
  fCon: Boolean;
  public
  //procedure OnSocketEvent(Sender: TObject; Socket: TCustomWinSocket;
  //                SocketEvent: TSocketEvent);
  procedure OnConect(Sender: TObject);
  {this OnConect and OnRecieve are like the TNotifyEvent with a
  (Sender: TObject)}
  procedure OnRecieve(Sender: TObject);
  Constructor Create;
  end;



var
hNoSee: Integer = 0;
Oz1: TOzObject;
Int1: Integer = 0;


{define your TOzObject below}
constructor TOzObject.Create;
begin
fCon := False;
Inc(Int1);
end;

procedure TOzObject.OnConect(Sender: TObject);
begin
fCon := True;
Inc(Int1);
end;

procedure TOzObject.OnRecieve(Sender: TObject);
begin
fCon := True;
Dec(Int1);
end;

{procedure TOzObject.OnSocketEvent(Sender: TObject; Socket: TCustomWinSocket;
                  SocketEvent: TSocketEvent);
begin
fCon := True;
end;}

// below is the windows WindowProc
function MessageFunc(hWnd,Msg,wParam,lParam:Integer):Integer; stdcall;
begin
case Msg of
  WM_TIMER: if WParam = 1 then
    begin
    KillTimer(hWnd, 1);
    if MessageBox(0, 'Do You Want To End this Conect Program Now ? ?',
               '? ? Exit Program ?', MB_YESNO or MB_ICONQUESTION) = ID_YES then
      PostMessage(hWnd, WM_CLOSE, 0, 0)
      else
      SetTimer(hNoSee, 1, 10000, nil);
    end;
  WM_DESTROY: PostQuitMessage(0);
  end;
Result := DefWindowProc(hWnd,Msg,wParam,lParam);
end;



function StartUp: Boolean;
var
WndClass: TWndClass;
begin
Result := False;
ZeroMemory(@WndClass, SizeOf(WndClass));
WndClass.lpfnWndProc := @MessageFunc;
WndClass.lpszClassName := 'Conect  Class';
WndClass.hInstance := hInstance;

if RegisterClass(WndClass) = 0 then Exit;

hNoSee := CreateWindowEx(WS_EX_TOOLWINDOW, WndClass.lpszClassName,
    'Conect', WS_POPUP, 0, 0, 0, 0, 0, 0, hInstance, nil);
if hNoSee = 0 then
  begin
  MessageBox(0, 'ERROR = Unable to Start this Conect Program', 'NO GO !', MB_ICONERROR);
  Exit
  end else
  Result := True;

{This Timer is not neccesary, but it is the only way to end this program,
since there is NO USER INPUT}
SetTimer(hNoSee, 1, 10000, nil);

Oz1 := TOzObject.Create;
//boSocket1 := TboScocket.Create;
//Oz1.OnRecieve := boSocket1.OnRecieve;
end;

procedure RunMsgLoop;
var
MainMsg: TMSG;
begin
{this RunMsgLoop procedure will run the GetMessage Loop to keep
this program running.}

while GetMessage(MainMsg,0,0,0) do
  begin
  TranslateMessage(MainMsg);
  DispatchMessage(MainMsg);
  end;
end;

initialization

finalization
if Oz1 <> nil then
  Oz1.Free;

end.


= = = = = = = = = = = = = = = = = = = = = =

this will make an invisible window and get youe program in the windows Message queue, this will creat an Object  TOzObject  so you can get Events for your  onReceive  or whatever socket events

there is a Timer in this so you can End the program

ask questions if you neeed more
0
 
mokuleCommented:
You can create Console Application
0
 
shaneholmesCommented:
NO GUI Delphi applications - Page 1/2
Creating a console mode application with Delphi; a text-mode program that runs without a graphical interface. Even more: see how to capture the output of a console application in a GUI Delphi program.

http://delphi.about.com/library/weekly/aa091101a.htm

NO GUI Delphi applications - Page 2/2
Creating a console mode application with Delphi; a text-mode program that runs without a graphical interface. Even more: see how to capture the output of a console application in a GUI Delphi program.

http://delphi.about.com/library/weekly/aa091101b.htm

Shane
0
[Webinar] Improve your customer journey

A positive customer journey is important in attracting and retaining business. To improve this experience, you can use Google Maps APIs to increase checkout conversions, boost user engagement, and optimize order fulfillment. Learn how in this webinar presented by Dito.

 
shaneholmesCommented:
Or you could try using ASPack on your Executables to shrink them - thats what i use.

www.aspack.com


Shane
0
 
shaneholmesCommented:
Here is another good simple article on Consoles Applications in Delphi!

Console applications in Delphi
http://www.geocities.com/SiliconValley/Lakes/1636/con_apps.htm

How to determine the output of a console application
http://delphi.about.com/cs/adptips2003/a/bltip0803_5.htm

Shane




0
 
Ivanov_GCommented:

   If you want console application here is what you have to do ...

   1) Project / View Source to open the DPR file
   2) in Uses clause remove Form unit
   3) on the second line after project clause put {$APPTYPE CONSOLE}
   4) remove Unit1 from the project ...
0
 
mokuleCommented:
Or just by clicking

File / New / Other /Console Application
0
 
AlievCommented:
If you want that your exe file will small, do everything with WinAPI.
Other way is to compress with any utilitties.
UPX Graphical
AsPack(www.aspack.com)
PeCompact(www.collakesoftware.com) and others.
0
 
bpanaCommented:
Hi,

if you don't want a console application, in the dpr remove the Forms from the uses clause, {$R *.res}, Application ...

here's an example:

program Project1;

function Sum(a, b : integer): integer;
begin
  Result := a+b;
end;

var
  mySum : integer;
begin
  mySum := Sum(1, 3);
end.

Bogdan
0
 
Sam80Author Commented:
I did followed what you say, but what about the DOS window? how Can I hide it ? I use console application .

Sam
0
 
shaneholmesCommented:
If you have gone the Console Application route, just

comment out {$APPTYPE CONSOLE}


Shane
0
 
shaneholmesCommented:
// {$APPTYPE CONSOLE}

Shane
0
 
bpanaCommented:
yes, remove {$APPTYPE CONSOLE}

Bogdan
0
 
Sam80Author Commented:
In console application , I want to hold my application for several minutes, not terminated as it run to the last code. how to do it ??

Sam
0
 
Ivanov_GCommented:
program Project1;

{$APPTYPE CONSOLE}

uses
  Windows, SysUtils;

{$R *.RES}

begin
  WriteLn('Hello World!');

  // your code here ... Do what ever you want

  // some delay
  Sleep(1000);

  WriteLn('Finishing...');
  Halt(0);
end.
0
 
mornaoCommented:
Three things -

1. Debug (project..Options..Compiler tab, Linker tab) will bloat your programs, sometimes up to 8 times their normal size. Removal of the Debugging options and Include TD32  debug info will shrink the programs footprint (but will no longer be able to debug).  In addition delete the debug lines from the top of the source ({INCLUDE DEBUG} etc).

2. an excellent article sequence on creating small Delphi programs is available here .

http://www.angelfire.com/hi5/delphizeus/dpr1.html

3. Use diskIO once and keep inline - such as using inifiles to load at creation internal data then use saved retrieved values rather than getting them again... and again... and again...
0
 
Sam80Author Commented:
Initially , I want to create a little chat program, but it seems different between console application and the normal application, I cannot write the codes in the socket  event, like the onReceive and onaccept events.

Sam
0
All Courses

From novice to tech pro — start learning today.