English 中文(简体)
我需要帮助如何执行在目标检查员上可以显示的班级。
原标题:I need help on how to implement class that can be shown in object Inspector

i)

...
  TDispPitch = class
  private
    iLineSize: Integer;
    iLineColor: TColor;
    bDisplayAccent: Boolean;
    bVisible: Boolean;
  published
    property LineSize : Integer read iLineSize write iLineSize;
    ...etc
  end;
...

并且i 希望在目标Insepector中看到这一特征,以ed住环境。

i 尝试添加

property DispPitch: TDispPitch read FDispPitch write FDispPitch. like 

迪斯巴奇可以显示,但不能看到其财产。 如线索、线孔等。

最佳回答

您的班子必须来自<条码>TPersistent或后代,以便在目标检查员中提供:

TDispPitch = class(TPersistent)
private
  ...
published
  property ...
  ...
end;

参考文献:

TPersistent is the ancestor for all objects that have assignment and streaming capabilities.

问题回答

班级需要从<代码>TPersistent中找到,并应当采用A Assign(or AssignTo())方法,同时暴露一个。 OnChange 活动使含铅类能够应对变化,例如:

type
  TDispPitch = class(TPersistent)
  private 
    iLineSize: Integer; 
    iLineColor: TColor; 
    bDisplayAccent: Boolean; 
    bVisible: Boolean; 
    FOnChange: TNotifyEvent;
    procedure Changed;
    procedure SetLineSize(Value : Integer); 
    procedure SetLineColor(Value: TColor); 
    procedure SetDisplayAccent(Value: Boolean); 
    procedure SetVisible(Value: Boolean); 
  public
    procedure Assign(Source: TPersistent); override;
    property OnChange: TNotifyEvent read FOnChange write FOnChange;
  published 
    property LineSize : Integer read iLineSize write SetLineSize; 
    property LineColor: TColor read iLineColor write SetLineColor; 
    property DisplayAccent: Boolean read bDisplayAccent write SetDisplayAccent; 
    property Visible: Boolean read bVisible write SetVisible; 
  end; 

procedure TDispPitch.Assign(Source: TPersistent);
var
  LSource: TDispPitch;
begin
  if Source is TDispPitch then
  begin
    LSource := TDispPitch(Source);
    iLineSize := LSource.LineSize;
    iLineColor := LSource.LineColor; 
    bDisplayAccent := LSource.DisplayAccent; 
    bVisible := LSource.Visible; 
    Changed;
  end else
    inherited;
end;

procedure TDispPitch.Changed;
begin
  if FOnChange <> nil then FOnChange(Self);
end;

procedure TDispPitch.SetLineSize(Value : Integer);
begin
  if iLineSize <> Value then
  begin
    iLineSize := Value;
    Changed;
  end;
end;

procedure TDispPitch.SetLineColor(Value: TColor); 
begin
  if iLineColor <> Value then
  begin
    iLineColor := Value;
    Changed;
  end;
end;

procedure TDispPitch.SetDisplayAccent(Value: Boolean); 
begin
  if bDisplayAccent <> Value then
  begin
    bDisplayAccent := Value;
    Changed;
  end;
end;

procedure TDispPitch.SetVisible(Value: Boolean); 
begin
  if bVisible <> Value then
  begin
    bVisible := Value;
    Changed;
  end;
end;

接着,你也这样做:

type
  TSomeOtherClass = class(...)
  private
    FDispPitch: TDispPitch;
    procedure DispPitchChanged(Sender: TObject);
    procedure SetDispPitch(Value: TDispPitch);
  public
    constructor Create; override;
    destructor Destroy; override;
  published
    property DispPitch: TDispPitch read FDispPitch write SetDispPitch;
  end;

constructor TSomeOtherClass.Create;
begin
  inherited;
  FDispPitch := TDispPitch.Create;
end;

destructor TSomeOtherClass.Destroy;
begin
  FDispPitch.Free;
  inherited;
end;

procedure TSomeOtherClass.DispPitchChanged(Sender: TObject);
begin
  ... use new FDispPitch values as needed...
end;

procedure TSomeOtherClass.SetDispPitch(Value: TDispPitch);
begin
  FDispPitch.Assign(Value);
end;




相关问题
determining the character set to use

my delphi 2009 app has a basic translation system that uses GNUGetText. i had used some win API calls to prepare the fonts. i thought it was working correctly until recently when someone from Malta ...

Help with strange Delphi 5 IDE problems

Ok, I m going nuts here. For the last (almost) four years, I ve been putting up with some extremely bad behavior from my Delphi 5 IDE. Problems include: Seemingly random errors in coride50.bpl ...

How to write a Remote DataModule to run on a linux server?

i would like to know if there are any solution to do this. Does anyone? The big picture: I want to access data over the web, using my delphi thin clients. But i´would like to keep my server/service ...

How convert string to integer in Oxygene

In Delphi, there is a function StrToInt() that converts a string to an integer value; there is also IntToStr(), which does the reverse. These functions doesn t appear to be part of Oxygene, and I can ...

Quick padding of a string in Delphi

I was trying to speed up a certain routine in an application, and my profiler, AQTime, identified one method in particular as a bottleneck. The method has been with us for years, and is part of a "...

热门标签