想法子帮忙瘦身啊:delphi编译出的可执行文件稍多写点就要1M了,这太肥了吧.. (100分)

我还见过!20M 的exe那
 
是啊 尽量不要用无关的第三方构件 比如皮肤类 我用DELPHI写过一个13K的MP3播放器(用
ASPACK压缩过 没压缩前是18K) 应该来说delphi写的软件会比vb的要小
 
to panxiaosen:
18k...如何写出来的?都用api了吗...?
 
把下面的代码复制并存为testwindow.dpr,再编译一下看看多大。
Copyright (C)Amigreen Software 1998
-----
program testwindow;

uses
Windows,
Messages;

var
WinClass: TWndClassA;
Inst, Handle, Button1, Label1, Edit1: Integer;
Msg: TMsg;
hFont: Integer;

{ Checks if typed password is 'Amigreen' and shows Message }
procedure CheckPassword;
var
Textlength: Integer;
Text: PChar;
begin
TextLength := GetWindowTextLength(Edit1);
if TextLength = 8 then
begin
GetMem(Text, TextLength + 1);
GetWindowText(Edit1, Text, TextLength + 1);
if Text = 'Amigreen' then
begin
MessageBoxA(Handle, 'Password is correct.', 'Password check', MB_OK);
FreeMem(Text, TextLength + 1);
Exit;
end;
end;
MessageBoxA(Handle, 'Password is incorrect.', 'Password check', MB_OK);
end;

{ Custom WindowProc function }
function WindowProc(hWnd, uMsg, wParam, lParam: Integer): Integer
stdcall;
begin
Result := DefWindowProc(hWnd, uMsg, wParam, lParam);
{ Checks for messages }
if (lParam = Button1) and (uMsg = WM_COMMAND) then
CheckPassword;
if uMsg = WM_DESTROY then
Halt;
end;

begin
{ ** Register Custom WndClass ** }
Inst := hInstance;
with WinClass do
begin
style := CS_CLASSDC or CS_PARENTDC;
lpfnWndProc := @WindowProc;
hInstance := Inst;
hbrBackground := color_btnface + 1;
lpszClassname := 'AG_TESTWINDOW';
hCursor := LoadCursor(0, IDC_ARROW);
end
{ with }
RegisterClass(WinClass);

{ ** Create Main Window ** }
Handle := CreateWindowEx(WS_EX_WINDOWEDGE, 'AG_TESTWINDOW', 'Amigreen TestWindow 1.00',
WS_VISIBLE or WS_SIZEBOX or WS_CAPTION or WS_SYSMENU,
363, 278, 305, 65, 0, 0, Inst, nil);
{ ** Create a button ** }
Button1 := CreateWindow('Button', 'OK', WS_VISIBLE or WS_CHILD or BS_PUSHLIKE or BS_TEXT,
216, 8, 75, 25, handle, 0, Inst, nil);
{ ** Create a label (static) ** }
Label1 := Createwindow('Static', '', WS_VISIBLE or WS_CHILD or SS_LEFT,
8, 12, 76, 13, Handle, 0, Inst, nil);

{ ** Create an edit field ** }
Edit1 := CreateWindowEx(WS_EX_CLIENTEDGE, 'Edit', '', WS_CHILD or WS_VISIBLE or
WS_BORDER or ES_PASSWORD, 88, 8, 121, 21, Handle, 0, Inst, nil);

{ ** Create Font Handle ** }
hFont := CreateFont(-11, 0, 0, 0, 400, 0, 0, 0, DEFAULT_CHARSET,
OUT_DEFAULT_PRECIS, CLIP_DEFAULT_PRECIS, DEFAULT_QUALITY,
DEFAULT_PITCH or FF_DONTCARE, 'MS Sans Serif');

{ Change fonts }
if hFont <> 0 then
begin
SendMessage(Button1, WM_SETFONT, hFont, 0);
SendMessage(Label1, WM_SETFONT, hFont, 0);
SendMessage(Edit1, WM_SETFONT, hFont, 0);
end;
{ Change label (static) text }
SetWindowText(Label1, 'Enter password:');
{ Set the focus to the edit control }
SetFocus(Edit1);

UpdateWindow(Handle);

{ ** Message Loop ** }
while(GetMessage(Msg,Handle, 0, 0)) do
begin
TranslateMessage(msg);
DispatchMessage(msg);
end
{ with }
end.
-----
 
楼上说得不错, 去掉一些不用的单元, 也可以减肥, 不过前提是你确实不用他们。

还有一个方法是: Build with runtime pakage(使用运行期包),那么所有的组件, 包括
Delphi自己的一些系统单元, 统统都在运行期包里(*.bpl)了。可执行文件永远都是300k
到500k左右。不过发布时要把这一堆bpl文件全拷贝过去, 一个不能少。

对于在程序里使用了大量图片的情况, 只好请AsPack这位尊神了。
 
aspack,其实如果软件功能多值那么大个的话,那就让它大好了,反正又不像早些年那样心痛空间了。
 
对呀,分包最好,用*.bpl,再把程序打包,安装时这些bpl都放到系统目录去,这样你的应用程序就只有几百k了,而且这种方法方便以后升级什么的。
 
好象没什么办法了?
等Delphi 8 出来,直接转成.net(如果可以的话)的应用程序,应该会很小吧?
分成DLL比较麻烦,还是用ASPACK比较快速
唉,现在我的问题更严重,用ASPack压缩后还有5M多呢,你说怎么办!
未压缩前: 21.9 MB (22,971,392 bytes) [:D][:D][:D]
 
to youyou
是的 用MCI命令来播放MP3的 www.fxmake.com/player.exe
需要源代码和我联系
 
几兆的文件大吗?OFFICE XP里边一个MSO.DLL WinXP Shell32.DLL都接近10M
少用第三方控件,压缩是一个最好的办法
不过向xianjun的21.9M的东西是有些恐怖的。
推荐一个做法可以降低大小
少用ImageList直接存储很多Bitmap,比如你只需要16色的东西,但是在32位色的环境下开发,在*.dfm里边存储的是32色的东西,这样如果有很多图,大小会飞速增长,不信你可以在系统的32位色和256色的环境下编译同一个程序,大小是不一样的(ImageList)所以建议采用RES资源文件,代码加载
(在最后优化期间进行,开发期间可以直接使用)
至于运行期间的大小,压缩是不起作用的,也没有好办法
 
to panxiaosen:
我的mail:linyouou@21cn.com 谢谢..


 
发一份 aspack给我:llz1972@21cn.com
thanks a lot
 
aspack网上搜索一大堆...
 

Similar threads

S
回复
0
查看
3K
SUNSTONE的Delphi笔记
S
S
回复
0
查看
2K
SUNSTONE的Delphi笔记
S
D
回复
0
查看
902
DelphiTeacher的专栏
D
I
回复
0
查看
369
import
I
I
回复
0
查看
722
import
I
顶部