正在写一个小程序,里面有很多form都会用到TDateTimePicker,现在想让TDateTimePicker默认显示系统当前时间,但是不想在每个formcreat里重复写,想问问写个过程让每个formcreat调用该怎么写,我已经默认让每个TDateTimePicker名称的前三个字为相同的字了,希望能有高手指点,急,希望能有代码赐教,谢谢各位了.保证及时上分

解决方案 »

  1.   

    procedure FormatTDateTimePicker(tempdtp:TDateTimePicker);
    begin
      tempdtp.DateTime := now;
    end;
      

  2.   

    function FindDateTimePicker(Owner: TComponent; const SubName: String; const DT: TDateTime): Boolean;
    var
      I: Integer;
      FComp: TComponent;
    begin
      Result := False;
      if Assigned(Owner) then
        for I := 0 to Owner.ComponentCount - 1 do
        begin
          FComp := Owner.Components[I];
          Result := (FComp is TDateTimePicker) and (Pos(SubName, FComp.Name) > 0);
          if Result then
            TDateTimePicker(FComp).DateTime := DT
          else Result := FindDateTimePicker(FComp, SubName, DT);
        end;
    end;
      

  3.   

    你写一个过程再调用,我觉得还不如直接写一句方便
    DateTimePicker.DateTime:= now;
      

  4.   

    自己写类嘛,继承TDateTimePicker 重写构造函数!easy
      

  5.   

    供参考:
        for x := 0 to Self.ComponentCount – 1 do 
        if Self.Components[x] is TDateTimePicker then 
        TDateTimePicker(Self.Components[x]).DateTime := now;