微信公众号 
图码生活

每天发布有五花八门的文章,各种有趣的知识等,期待您的订阅与参与
电脑报 1992-2001 十年文章全集
电脑报 1992-2001 十年文章全集
包含从 1992 年 - 2001 年间,两万余篇期刊文章,查询最少输入两个字符
随便看看
读取中
读取中
标题菜鸟捉虫(36)
栏目软件世界
发布2001年36期
  上期正确答案:
  在DLL代码中,很明显的一个错误就是没有exports段将ShowAboutForm函数输出。这样主程序将无法使用这个函数。另外,如果用AboutForm.Show则会看不到窗体,因为它刚一显示出来就被Free掉。另外,因为Show所显示的窗体不是无模式窗体,使用ShowModal显示窗体后,窗体在没有关闭时将不会被Free掉。
   获奖名单:
  辽宁 吴 新  山东 张 鹏
  四川 彭宇正  湖南 丁 益
  广东 刘远毅
  以上幸运读者将获得电脑报最新出品的《电脑报系列配套光盘》杂志一套。
   本期题目:
  本期的题目要求我们动态创建6个按钮,并在单击某个按钮显示出所单击按钮的Caption值。下面的程序代码就是实现这个功能的,但是存在一些错误,请将这些错误找出来:
  ……
  uses
  Windows, Messages, SysUtils, Classes, Graphics, Controls,Forms, Dialogs;
  type
  ……
  private
  procedure DoClick(Sender:TObject);
  var
  Form1:TForm1;
  vBtn:Array[0..5]of TButton;
  StrLst:TStringList;
  ……
  procedure TForm1.DoClick(Sender:TObject);
  //响应单击事件
  var
  i:integer
  begin
  for i:=0 to 5 do
  begin
  if Sender:= vBtn[i] then
  ShowMessage('你单击的按钮是:' + vBtn[i].Caption);
  end;
  end;
  procedure TForm1.FormCreate(Sender:TObject);
  var
  i,vHeight:integer
  begin
  StrLst:=TStringList.Create;
  StrLst.Add('VB');
  StrLst.Add('VC');
  StrLst.Add('Delphi);
  StrLst.Add('Java);
  StrLst.Add('C#');
  StrLst.Add('ASP.NET');
  vHeight:=50;
  for i:=0 to 5 do
  begin
  vBtn[i]:=TButton.Create(Form1);//创建按钮
  vBtn[i].Caption:=StrLst.Strings[i];
  vBtn[i].Left:=0
  if i=0 then
  vBtn[i].Top:=0
  else
  vBtn[i].Top:=vBtn[i-1].Top + vHeight;
  vBtn[i].Width:=200;
  vBtn[i].Height:=vHeight;
  vBtn[i].OnClick:=DoClick;
  end;
  end;
  procedure TForm1.FormDestroy(Sender:TObject);
  var
  i:integer
  begin
  //释放资源
  StrLst.Free
  for i:=0 to 5 do
  vBtn[i].Free
  end;
  end