哪位高手能给出源代码范例啊,我的总是调不通。

解决方案 »

  1.   

    unit uDemoPropertyEdit;interfaceuses
      DesignEditors,  
      DesignIntf,
      Dialogs, SysUtils, StdCtrls, Classes;type  TDemoEdit = class(TEdit)
      private
        FFileName: string;
      published
        property FileName: string read FFileName write FFileName;
      end;  TDemoFileNameProperty = class(TPropertyEditor)
      public
        procedure Edit; override;
        function  GetAttributes: TPropertyAttributes; override;
        function  GetValue: string; override;
        procedure SetValue(const Value: string); override;
      end;procedure Register;implementation{ TDemoFileNameProperty }procedure TDemoFileNameProperty.Edit;
    var
      OpenD: TOpenDialog;
    begin
      OpenD := TOpenDialog.Create(nil);
      OpenD.Title := 'Select a text file';
      OpenD.Filter := 'Text files(*.txt)|*.txt';
      OpenD.DefaultExt := 'txt';
      if FileExists(Value) then OpenD.InitialDir := ExtractFileDir(Value);
      OpenD.FileName := Value;
      if OpenD.Execute then begin
        SetValue(OpenD.FileName);
      end;
      OpenD.Free;
    end;function  TDemoFileNameProperty.GetAttributes: TPropertyAttributes;
    begin
      Result := [paDialog];
    end;function  TDemoFileNameProperty.GetValue: string;
    begin
      Result := GetStrValue;
    end;procedure TDemoFileNameProperty.SetValue(const Value: string);
    begin
      SetStrValue(Value);
    end;procedure Register;
    begin
      RegisterComponents('Samples', [TDemoEdit]);
      RegisterPropertyEditor(TypeInfo(string), TDemoEdit,
                             'FileName', TDemoFileNameProperty);
    end;end.