我正在开发 Delphi -7
中的自定义组件我有一些published
特性
private
{ Private declarations }
FFolderzip ,Fimagezip,Ftextzip,FActivatezipComp : Boolean;
FMessagebo : string;
published
{ Published declarations }
{component Properties}
{#1.Folder Zip}
property ZipFolder : Boolean read FFolderzip write FFolderzip default False;
{#2.Send imagezip ?}
property ZipImage : Boolean read Fimagezip write Fimagezip default False;
{#3.text files}
property ZipText : Boolean read Ftextzip write Ftextzip default False;
{#4.message}
property ZipMessage: String read FMessagebo write FMessagebo ;
{#5.Activate }
property ActivateZipper: Boolean read FActivatezipComp write FActivatezipComp Default false;
end;
当用户将组件放在应用程序上时,
ActivateZipper
属性为用户提供了激活/启用或停用/禁用组件执行的选项。组件创建文件
所以在构造函数中我有这个,
CreateATextFileProc
将在应用程序文件夹中创建文件。因此,如果我在构造函数中检查 ActivateZipper
是真的还是假的。。我有一个
constructor
constructor TcomProj.Create(aOwner: TComponent);
begin
inherited;
if ActivateZipper then CreateATextFileProc;
end;
ActivateZipper
即使我在对象检查器中将其设置为 true,它也始终为 false。如何禁止组件使用已发布的属性?
最佳答案
构造函数为时过早。设计时属性值尚未流入组件。您需要等到组件的 Loaded()
在您可以对这些值采取行动之前调用方法。如果您在运行时动态创建组件,您还需要一个属性 setter ,因为没有 DFM 值,因此 Loaded()
不会被调用。
type
TcomProj = class(TComponent)
private
...
procedure SetActivateZipper(Value: Boolean);
protected
procedure Loaded; override;
published
property ActivateZipper: Boolean read FActivatezipComp write SetActivateZipper;
end;
procedure TcomProj.SetActivateZipper(Value: Boolean);
begin
if FActivatezipComp <> Value then
begin
FActivatezipComp := Value;
if ActivateZipper and ((ComponentState * [csDesigning, csLoading, csLoading]) = []) then
CreateATextFileProc;
end;
end;
procedure TcomProj.Loaded;
begin
inherited;
if ActivateZipper then CreateATextFileProc;
end;
关于delphi - 禁用/停用具有已发布属性的自定义组件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11259487/