请问各位大虾本人需要向,要显示的窗体中传递参数,使得窗体根据不同的参数显示不同的内容,是重载该窗体的FormCreate函数还是FormShow函数,或者是其它什么函数?希望能够提供例程。(急)

解决方案 »

  1.   

    重载或自定义一个构造函数,或者在B设一个Class Function:
    type 
      TForm2 = class(TForm)
      ...
      public
        class function CreateForm2(const AMyParam: string): TForm;
      end;
    ...
    class function TForm2.CreateForm2(const AMyParam: string): TForm;
    begin
      Result := nil;
      if AMyParam = 'Create' then
        Result := TForm2.Create(Application);
    end;调用的时候:
      Form2 := TForm2.CreateForm2('Create');或使用ParamStr和ParamCount函数。其中ParamStr(0)返回的是当前程序名,如C:\TEST\MYPROG.EXE,ParamStr(1)返回第一个参数,以此类推;ParamCount则是参数个数。示例如下:  var   I: Word;  Y: Integer;  begin   Y := 10;   for I := 1 to ParamCount do begin   Canvas.TextOut(5, Y, ParamStr(I));   Y := Y + Canvas.TextHeight(ParamStr(I)) + 5;   end;  end;
      

  2.   

    with Form2.Create(Self) do
    begin
      Caption := 'aaa';
      Edit1.Text := 'bbb';
      AProperty := 123; //一个自定义的属性
      try
        ShowModal;
      finally
        Free;
      end;
    end;