Solved

How to program a small delphi application?

Posted on 2004-04-25
20
485 Views
Last Modified: 2010-04-05
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
0
Comment
Question by:Sam80
[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
  • 5
  • 3
  • 2
  • +5
20 Comments
 
LVL 17

Expert Comment

by:mokule
ID: 10912088
You can create Console Application
0
 
LVL 11

Expert Comment

by:shaneholmes
ID: 10912145
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
 
LVL 11

Expert Comment

by:shaneholmes
ID: 10912148
Or you could try using ASPack on your Executables to shrink them - thats what i use.

www.aspack.com


Shane
0
Technology Partners: 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 11

Expert Comment

by:shaneholmes
ID: 10912163
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
 
LVL 12

Expert Comment

by:Ivanov_G
ID: 10912179

   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
 
LVL 17

Expert Comment

by:mokule
ID: 10912298
Or just by clicking

File / New / Other /Console Application
0
 
LVL 3

Expert Comment

by:Aliev
ID: 10912561
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
 
LVL 6

Expert Comment

by:bpana
ID: 10913012
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
 

Author Comment

by:Sam80
ID: 10919578
I did followed what you say, but what about the DOS window? how Can I hide it ? I use console application .

Sam
0
 
LVL 11

Expert Comment

by:shaneholmes
ID: 10919670
If you have gone the Console Application route, just

comment out {$APPTYPE CONSOLE}


Shane
0
 
LVL 11

Expert Comment

by:shaneholmes
ID: 10919677
// {$APPTYPE CONSOLE}

Shane
0
 
LVL 34

Expert Comment

by:Slick812
ID: 10922385
0
 
LVL 6

Expert Comment

by:bpana
ID: 10922734
yes, remove {$APPTYPE CONSOLE}

Bogdan
0
 

Author Comment

by:Sam80
ID: 10948501
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
 
LVL 12

Expert Comment

by:Ivanov_G
ID: 10948577
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
 
LVL 1

Expert Comment

by:mornao
ID: 10987368
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
 

Author Comment

by:Sam80
ID: 10997040
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
 
LVL 34

Accepted Solution

by:
Slick812 earned 50 total points
ID: 10999981
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

Featured Post

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

The uses clause is one of those things that just tends to grow and grow. Most of the time this is in the main form, as it's from this form that all others are called. If you have a big application (including many forms), the uses clause in the in…
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 is a high-level webinar that covers the history of enterprise open source database use. It addresses both the advantages companies see in using open source database technologies, as well as the fears and reservations they might have. In this…
Michael from AdRem Software explains how to view the most utilized and worst performing nodes in your network, by accessing the Top Charts view in NetCrunch network monitor (https://www.adremsoft.com/). Top Charts is a view in which you can set seve…

734 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