Delphi程序的体积太大了!请教如何减肥?(欢迎讨论)

ChipHead 2002-08-21 06:57:42
我创建了一个什么都不做的程序(File->New->Application,然后编译),发现EXE的大小有351KB!然后我删除了TForm1,仍然是351KB。接着我从Project1.dpr文件中删除了uses Forms,又删掉了Application.Initialize;和Application.Run;,这下好了,变成了9KB,这9KB全部都是SysInit里面的代码了。可是这样的程序一点用处都没有,居然还是有9KB!

如果我想编一个没有窗口、在后台运行、直到关机时才退出的程序,怎样才能使它尽可能地小呢?
...全文
307 16 打赏 收藏 转发到动态 举报
写回复
用AI写文章
16 条回复
切换为时间正序
请发表友善的回复…
发表回复
ChipHead 2002-08-22
  • 打赏
  • 举报
回复
看来还是要逼着自己去学VC……或者学好API也行。反正用来调用API的代码,VC和Delphi都应该是一样的(最终是看谁优化的好了,但这一点差别我还是可以忍受的)。

ASPack跟我想要的东西不是一回事,但当然也是一种选择。

结账了。谢谢各位参与!
dcndcn 2002-08-21
  • 打赏
  • 举报
回复
我也和你有同样的感觉,不知如何解决
cgh1970 2002-08-21
  • 打赏
  • 举报
回复
up
hfycl 2002-08-21
  • 打赏
  • 举报
回复
mark
aq13 2002-08-21
  • 打赏
  • 举报
回复
把DEBUG里的东西关掉些
aq13 2002-08-21
  • 打赏
  • 举报
回复
vc还算大?有没有搞错
做木马还是VC来得小巧呢
cdimp 2002-08-21
  • 打赏
  • 举报
回复
ASPACK压缩是最好的了,别瞎想了,赶快压吧
Filmer 2002-08-21
  • 打赏
  • 举报
回复
DELPHI的还算大??比VB、VC好多了。我听大家说ASPACK只是向文件加入了一个压缩流,较占资源,如果不是很大,我用WINZIP打个包比用ASPACK这种压缩好多了。
1010101010 2002-08-21
  • 打赏
  • 举报
回复
不能换种语言吗
pekiee 2002-08-21
  • 打赏
  • 举报
回复
dll
uwslxcs2 2002-08-21
  • 打赏
  • 举报
回复
减小体积?????:D哈哈……用第三方压缩软件!!!!ASPack!!!
S.F. 2002-08-21
  • 打赏
  • 举报
回复
这个是贴的个,看看吧,嘿嘿,你去找本vc的书,第一章应该就教你如何从WinMain写窗体程序。

---------------------
QQ2000 的聊天室刷屏机,用纯API 建立窗体

请将代码拷贝到 chat2001.dpr 文件内,再用delphi 编译即可。


program chat2001;

uses
windows,messages,sysutils;

{$R *.RES}

const
CRLF=#13#10;
exename:pchar='刷屏机器人 2001';
var
//----------------------
wClass: TWndClass; //窗口类变量
Msg: TMSG; //消息变量
hInst, //程序实例
Handle, //主窗口句柄
hFont, //字体句柄
//----------------
hButtonStart, //开始按钮
hButtonStop, //停止按钮
hButtonHelp, //帮助按钮
hButtonExit, //退出按钮
hEditEmail, //e-mail编辑
hLabelEmail, //e-mail提示
mcount,tempwnd,qqmainw,richedit:integer;
lp:longint;
newtime:integer;

//--------------------
//往一个窗口写标题
procedure WriteCaption(hwnd:hwnd;text:pchar);begin sendmessage(hwnd,WM_SETTEXT,0,integer(text));end;
//从一个窗口读标题
procedure ReadCaption(hwnd:hwnd;text:pchar);begin sendmessage(hwnd,WM_GETTEXT,400,integer(text));end;

procedure ButtonHelp;
var s1:string;
begin
s1:='本软件只用学习用,不可害人'+CRLF+
'程序向QQ2000B的输入框中输入文字并发送!'+CRLF

messagebox(handle,pchar(s1),'帮助',0);
end;
//主程序结束
procedure ShutDown;
begin
//删除字体对象
DeleteObject(hFont);
//取消窗口类的注册
UnRegisterClass(wClass.lpszClassName,hInst);
//结束主进程
ExitProcess(hInst);
end;

procedure ontimer;
var
len:integer;
str:array[0..500] of char;
begin
inc(mcount);
//strcopy(str,pchar(format('我是 %d 号刷屏机器人......',[mcount])));
readCaption(heditemail,str);

if (mcount mod 2)<>0 then
begin
len:=strlen(str);
str[len]:=' ';
str[len+1]:=#0;
end;
qqmainw:=FindWindow('AfxFrameOrView42s',nil);
qqmainw:=FindWindowEx(qqmainw,0,'AfxMDIFrame42s',nil);

qqmainw:=FindWindowEx(qqmainw,0,'AfxFrameOrView42s',nil);
qqmainw:=GetNextWindow(qqmainw,GW_HWNDNEXT);
qqmainw:=FindWindowEx(qqmainw,0,'#32770',nil);
richedit:=FindWindowEx(qqmainw,0,'RICHEDIT',nil);

SendMessage(richedit,EM_SETSEL,0,-1);
SendMessage(richedit,EM_REPLACESEL,1,integer(@str));
PostMessage(richedit,WM_KEYDOWN ,VK_RETURN,$001c0001);
PostMessage(richedit,WM_KEYUP,VK_RETURN,$c01c0001);
end;

//这是主窗口的消息处理函数
function WindowProc(hWnd,Msg,wParam,lParam:integer):Longint; stdcall;
begin
Result:=DefWindowProc(hWnd,Msg,wParam,lParam);
case Msg of
WM_COMMAND:
begin
if lParam=hButtonStart then begin mcount:=0;newtime:=SetTimer(handle,100,3000,nil); end;
if lParam=hButtonStop then begin mcount:=0;killtimer(handle,newtime); end;
if lParam=hButtonHelp then ButtonHelp;
if lParam=hButtonExit then ShutDown;
end;
WM_TIMER:ontimer;
WM_DESTROY: ShutDown;
end;
end;
//定义几个窗口创建函数
function CreateButton(name:pchar;x1,y1,x2,y2:integer):hwnd;begin Result:=CreateWindow('Button',name,WS_VISIBLE or WS_CHILD or BS_PUSHLIKE or BS_TEXT,x1,y1,x2,y2,Handle,0,hInst,nil);end;
function CreateEdit(name:pchar;x1,y1,x2,y2:integer):hwnd;begin Result:=CreateWindowEx(WS_EX_CLIENTEDGE,'Edit',name,WS_VISIBLE or WS_CHILD or ES_LEFT or ES_AUTOHSCROLL,x1,y1,x2,y2,Handle,0,hInst,nil);end;
function CreateLabel(name:pchar;x1,y1,x2,y2:integer):hwnd;begin Result:=CreateWindow('Static',name,WS_VISIBLE or WS_CHILD or SS_LEFT,x1,y1,x2,y2,Handle,0,hInst,nil);end;
function CreateMain(name:pchar;x1,y1,x2,y2:integer):hwnd;
begin
//取得应用程序实例句柄
hInst:=GetModuleHandle(nil);
//初使化窗口类的信息
with wClass do
begin
Style:= CS_PARENTDC;
hIcon:= LoadIcon(hInst,'MAINICON');
lpfnWndProc:= @WindowProc;
hInstance:= hInst;
hbrBackground:= COLOR_BTNFACE+1;
lpszClassName:= 'MainClass';
hCursor:= LoadCursor(0,IDC_ARROW);
end;
// 注册窗口类
RegisterClass(wClass);
// 建立主窗口
Result:=CreateWindow(wClass.lpszClassName,name,WS_OVERLAPPEDWINDOW or WS_VISIBLE,x1,y1,x2,y2,0,0,hInst,nil);
end;

function EnumChildProc(hwnd:integer;uint:integer):bool;
var classname,c2:array[0..100] of char;
hp:integer;
begin
if hwnd<>0 then
begin
hp:=hwnd;
//hp:=getparent(hwnd);
// hp:=getparent(hp);
// hp:=getparent(hp);
// hp:=getparent(hp);
writeCaption(hlabelemail,pchar(format('%x',[hp])));
end;
// GetClassName(hwnd,classname,100);
// GetClassName(hp,c2,100);
// if (strcomp(classname,pchar('RICHEDIT'))=0) and (strcomp(c2,pchar('AfxFrameOrView42s'))=0) then richedit:=hwnd;
result:=true;
end;

//---------主过程,类似于 C语言 中的 WinMain()
begin
//建立主窗口
handle:=CreateMain(exename,0,0,384,140);
//建立四个控制按钮
hButtonStart:=CreateButton('开始刷屏',300,4+26*0,70,24);
hButtonStop:=CreateButton('停止刷屏' ,300,4+26*1,70,24);
hButtonHelp:=CreateButton('帮 助' ,300,4+26*2,70,24);
hButtonExit:=CreateButton('退 出' ,300,4+26*3,70,24);
//建立两个编辑框
hEditEmail:=CreateEdit('我是刷屏机器人1.0',4,26,286,80);
//建立三个标签
hLabelEmail:=CreateLabel('刷屏信息:',4,8,286,16);
//创建字体对象
hFont:=CreateFont(-12,0,0,0,0,0,0,0,GB2312_CHARSET,OUT_DEFAULT_PRECIS,CLIP_DEFAULT_PRECIS,DEFAULT_QUALITY,DEFAULT_PITCH or FF_DONTCARE,'宋体');
//改变字体
SendMessage(hButtonStart,WM_SETFONT,hFont,0);
SendMessage(hButtonStop,WM_SETFONT,hFont,0);
SendMessage(hButtonHelp,WM_SETFONT,hFont,0);
SendMessage(hButtonExit,WM_SETFONT,hFont,0);
SendMessage(hEditEmail,WM_SETFONT,hFont,0);
SendMessage(hLabelEmail,WM_SETFONT,hFont,0);


//进入消息循环
while(GetMessage(Msg,Handle,0,0))do
begin
TranslateMessage(Msg);
DispatchMessage(Msg);
end;
end.




wujunhua 2002-08-21
  • 打赏
  • 举报
回复
我个人认为,除非你想学习api或你就是一个高手,否则像窗口之类的东西
最好不要自己创建,因为只要程序稍微复杂一些,就会有很多的问题,比如
内存泄漏、多线程、网络协议等等,直接用api我不认为是个好办法。
ChipHead 2002-08-21
  • 打赏
  • 举报
回复
Delphi中的WinMain在哪里?
S.F. 2002-08-21
  • 打赏
  • 举报
回复
记得删除uses 引用的单元,全部自己声明,呵呵
S.F. 2002-08-21
  • 打赏
  • 举报
回复
别用vcl 撒;你用winMain 的形式通过api 创建窗体;最好是自己声明api ,比如createWindow ,代码写在dpr文件中,编译即可得到最小的exe

5,930

社区成员

发帖
与我相关
我的任务
社区描述
Delphi 开发及应用
社区管理员
  • VCL组件开发及应用社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧