{ TMixedComponent }
TMixedComponent = class(TComponent)
private
FFileName: String;
published
property FileName : String read FFileName write FFileName;
{ Published declarations }
end;
{ TMixedFileNameProperty }
TMixedFileNameProperty = class(TPropertyEditor)
function AllEqual: boolean; override;
procedure Edit; override;
function GetAttributes: TPropertyAttributes; override;
function GetValue: string; override;
procedure SetValue (const Value: string); override;
end;
procedure Register;
implementation
procedure Register;
begin
RegisterPropertyEditor(TypeInfo(string), TMixedComponent, 'FileName', TMixedFileNameProperty);
RegisterComponents('Samples', [TMixedComponent]);
end;
function TMixedFileNameProperty.AllEqual: boolean;
var
FirstVal: string;
i: Integer;
begin
FirstVal := GetStrValue;
Result := True;
i := 1;
while Result and (i < PropCount) do
begin
Result := Result and (GetStrValueAt(i) = FirstVal);
Inc(i);
end;
end;
procedure TMixedFileNameProperty.Edit;
var
Dlg: TOpenDialog;
begin
Dlg := TOpenDialog.Create(Application);
try
with Dlg do
begin
Title := 'File for ' + TComponent(GetComponent(0)).Name;
FileName:= Value;
if Execute then Value := FileName;
end;
finally
FreeAndNil(Dlg);
end
end;
function TMixedFileNameProperty.GetAttributes: TPropertyAttributes;
begin
Result := [paDialog]
end;
function TMixedFileNameProperty.GetValue: string;
begin
Result := GetStrValue;
end;
procedure TMixedFileNameProperty.SetValue(const Value: string);
begin
SetStrValue(Value);
end;
轉貼至:http://edn.embarcadero.com/article/27717
編譯出現的問題排除:
USES DesignIntf,DesignEditors
並將 $(DELPHI)\Source\ToolsAPI 的DesignIntf.pas,DesignEditors.pas
放到
$(DELPHI)\Lib
並在PROJECT VIEW SOURCE requires部份加入 designide
轉貼至 http://delphi.ktop.com.tw/board.php?cid=30&fid=71&tid=85713
沒有留言:
張貼留言