在看题之前恳求大家一定要看下去,我已经发过一个类似的问题了没人给解答,3天了一直不明白下面的程序怎么实现的,再次恳求大家耐心看完,本人菜鸟分不多,希望还请多多包涵书上的一道实例是这样的,一共有2个窗体,窗体1上面有2个image和一个button,窗体2是一些设置选项
程序作用:点击窗体1上的button弹出窗体2,然后对上面的选项进行选择,确定后退出,窗体1的图片会进行对应的修改
程序设计界面在下面的网址
http://hi.baidu.com/xuminghui3821/blog/item/952bf33cf24770e23c6d97d4.html窗体1代码unit MoreF;interfaceuses
  Windows, Classes, Graphics, Forms,
  Controls, ConfDial, StdCtrls, ExtCtrls;type
  TForm1 = class(TForm)
    Image1: TImage;
    Image2: TImage;
    ConfigureButton: TButton;
    procedure ConfigureButtonClick(Sender: TObject);
    procedure FormCreate(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;var
  Form1: TForm1;implementation{$R *.DFM}procedure TForm1.ConfigureButtonClick(Sender: TObject);
begin
  ConfigureDialog.CheckBox1.Checked := image1.Visible;
  ConfigureDialog.CheckBox2.Checked := image2.Visible;
  if (image2.height=75) and (image2.width=75) then
    ConfigureDialog.RadioGroup1.itemindex:=0
  else
    ConfigureDialog.RadioGroup1.ItemIndex:=1;
  if (ConfigureDialog.ShowModal = mrOk) then
    begin
      Image1.Visible := ConfigureDialog.CheckBox1.Checked;
      Image2.Visible := ConfigureDialog.CheckBox2.Checked;
      if ConfigureDialog.RadioGroup1.ItemIndex=0 then
        begin
        image2.Left:=110;
        image2.Top:=60;
        image2.Height:=75;
        image2.Width:=75;
        end
      else if ConfigureDialog.RadioGroup1.ItemIndex=1 then
        begin
        image2.Top:=15;
        image2.Left:=70;
        image2.Height:=150;
        image2.Width:=150;
        end;
    end;
end;procedure TForm1.FormCreate(Sender: TObject);
begin
image1.Picture.LoadFromFile('1.bmp');
image2.Picture.loadfromfile('2.bmp');
end;end.
窗体2代码如下unit Confdial;interfaceuses
  Windows, Classes, Graphics, Forms,
  Controls, Buttons, StdCtrls, ExtCtrls;type
  TConfigureDialog = class(TForm)
    BitBtn1: TBitBtn;
    BitBtn2: TBitBtn;
    CheckBox1: TCheckBox;
    CheckBox2: TCheckBox;
    RadioGroup1: TRadioGroup;
  private
    { Private declarations }
  public
    OldHeight, NewHeight: Integer;
  end;var
  ConfigureDialog: TConfigureDialog;implementation{$R *.DFM}
end.
程序我能看明白  我就是不知道点击窗体1的设置按钮如何弹出窗体2的
另外我按照这个例子写窗体1代码的时候只要碰到窗体2的一些设置就会报错,
我不明白如何将窗体1的设置按钮与窗体2联系起来的,恳请各位高手帮帮忙吧,菜鸟真的很痛苦啊
另外是否跟
uses中的ConfDial, StdCtrls, ExtCtrls这3个东西有关?
我新建了一个窗体经过比较发现多出了这3个东西,不知道有什么关系,还请帮忙解释一下最后
别太在意分,我实在是没有分可给,像我这样的菜鸟,会经常提问问题的,得分途径也很少,但恰恰我是真正需要帮助的人,各位高手帮帮忙啊

解决方案 »

  1.   

    你要在 窗体1 中调用到 窗体2,就该引用 窗体2 所在的单元,也就是Confdial;
    从程序上看, 窗体2 是用Application自动创建的;
    StdCtrls-标准空间单元,拖个TButton的界面上再保存下,就会自动引用;
    ExtCtrls类似StdCtrls,还不明白自己查
      

  2.   

    拖个TButton的界面上再保存下,就会自动引用?
    能详细解释下么?
      

  3.   

    从程序上看, 窗体2 是用Application自动创建的;那样form1岂不是要取消掉?
      

  4.   

    "if (ConfigureDialog.ShowModal = mrOk) then" 这不就弹出窗体了么?窗体ConfigureDialog模式方式弹出,等待返回值,为 mrOK就执行下面的,跟OpenDialog和SaveDialog差不多,如:if   (savedialog.Execute) then showmessage('弹出');
      

  5.   

    project应该有类似代码:
        Application.CreateForm(TForm1, Form1);
        Application.CreateForm(TForm2, Form2);
    代表Application创建了 窗体1 跟 窗体2;
    但是为什么这出现 窗体1 呢?这里有个mainform的概念,排在前面的可视的就是mainform。可以尝试调换他们的创建顺序:
      Application.CreateForm(TForm2, Form2);
      Application.CreateForm(TForm1, Form1);
    这个可以看【Project Options】里
      

  6.   

    TForm1.Button1Click(Sender)
    begin
      Form2.show;或者
      Form2:=TForm2.Create(self);
      Form2.showmodal;
    end;
      

  7.   

    窗体创建默认是:visible:= False;
    所有需要Show、ShowModal方法让其显示出来;
    Show是普通显示,窗体1 跟 窗体2可以切换;
    ShowModal是模态显示,知道 窗体2 关闭,否则 窗体1 无法获得焦点(Focus);
      

  8.   

    要明白类与单元的关系(就像C++中类与源文件的关系):一个单元可以包含一个到多个类;
    要使用某个类,就要引用该类所在的单元(uses ...)。
      

  9.   

    if (ConfigureDialog.ShowModal = mrOk) then这句就是模式方式打开你所谓的窗体2,窗体2如果返回mrok(你在窗体2中一个button设置返回的值)那么就执行里面的内容
      

  10.   

        if (ConfigureDialog.ShowModal = mrOk) then
    这句话中ShowModal表示已模态窗体弹出ConfigureDialog窗体,mrOk是窗体关闭时的返回值,如果返回这个值就执行if语句了。
        你自己的写的时候报错,是因为你在Form1中 没有引用Confdial单元,可以手写,也可以File-Use Unit菜单进行操作。
      

  11.   

    弹出Form2,也就是ConfigureDialog窗体:ConfigureDialog.ShowModal = mrOk下边变量的赋值,也是直接取这个窗体上的。