Solved

How to program a small delphi application?

Posted on 2004-04-25
20
484 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
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!

 
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

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!

Question has a verified solution.

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

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 The parallel port is a very commonly known port, it was widely used to connect a printer to the PC, if you look at the back of your computer, for those who don't have newer computers, there will be a port with 25 pins and a small print…
Nobody understands Phishing better than an anti-spam company. That’s why we are providing Phishing Awareness Training to our customers. According to a report by Verizon, only 3% of targeted users report malicious emails to management. With compan…
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …

739 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