动态创建的form里有 TDateTimePicker
退出form 后如何得到DateTimePicker.date

解决方案 »

  1.   

    函数如下
    function inFind(const ACaption, APrompt,ADateLabel:string;var Value:String;FDate,TDate:TDateTime):Boolean;
       var FindForm:TForm;
           Edit:TEdit;
           Prompt,DateLabel: TLabel;
           DateF,DateT:TDateTimePicker;
      begin
        Result := False;
        FindForm := TForm.Create(Application);
        with FindForm do
        try
          Left := 202;
          Top := 374;
          Width := 295;
          Height := 186;
          Font.Charset := GB2312_CHARSET;
          Font.Name := '宋体';
          Font.Size :=9;
          Canvas.Font := Font;
          BorderStyle := bsDialog;
          Caption := ACaption;
          Position := poScreenCenter;      Prompt := TLabel.Create(FindForm);
          with Prompt do
          begin
            Parent := FindForm;
            Caption := APrompt;
            Left := 24;
            Top := 16;
            Width := 96;
            Height := 12;
            WordWrap := True;
          end;      DateLabel:= TLabel.Create(FindForm);
          with DateLabel do
          begin
            Parent := FindForm;
            Caption := ADateLabel;
            Left := 24;
            Top := 61;
            Width := 108;
            Height := 12;
            WordWrap := True;
          end;      Edit := TEdit.Create(FindForm);
          with Edit do
          begin
            Parent := FindForm;
            Left := 24;
            Top := 33;
            Width := 241;
            Height := 20;
            MaxLength := 255;
            Text := Value;
            SelectAll;
          end;      DateF:=TDateTimePicker.Create(FindForm);
          with DateF do
            begin
              Parent := FindForm;
              Left := 25;
              Top := 79;
              Width := 110;
              Height := 20;
              Date :=now;
              DateMode := dmUpDown;        end;      DateT:=TDateTimePicker.Create(FindForm);
          with DateT do
            begin
              Parent := FindForm;
              Left := 150;
               Top := 79;
             Width := 117;
            Height := 20;
              Date := now;
          DateMode := dmUpDown;
            end;      with TButton.Create(FindForm) do
          begin
            Parent := FindForm;
            Caption := '确定';
            ModalResult := mrOk;
            Default := True;
            Left := 73;
            Top := 115;
            Width := 75;
            Height := 25;
          end;      with TButton.Create(FindForm) do
          begin
            Parent := FindForm;
            Caption := '取消';
            ModalResult := mrCancel;
            Cancel := True;
            Left := 153;
            Top := 115;
            Width := 75;
            Height := 25;
          end;
          if ShowModal = mrOk then
          begin
            Value := Edit.Text;
            FDate:= DateF.Date;
            TDate:= DateT.Date;
            Result := True;
          end;
        finally
          FindForm.Free;
        end;
      end;
      

  2.   

    FDate:= DateF.Date;
    TDate:= DateT.Date;
    这不是已经访问了吗?
    你想问什么啊?