CnPack Forum


 
Subject: 关于CnOptionGroup使用的问题,请多多指教!
雨中雪
普通灌水员
Rank: 2



UID 41830
Digest Posts 0
Credits 79
Posts 29
点点分 79
Reading Access 10
Registered 2009-2-19
Status Offline
Post at 2009-2-19 17:01  Profile | Blog | P.M. 
关于CnOptionGroup使用的问题,请多多指教!

我创建一个类:以下是代码
unit GmConfig;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, ComCtrls;

type
  TGmConfig = class(TObject)
  private
   { Private declarations }
    FDate: TDate;
    FIntValue: Integer;
    procedure SetDate(const Value: TDate);
  public
    { Public declarations }
    property Date: TDate read FDate write SetDate;
    property IntValue: Integer read FIntValue write FIntValue;
  end;

implementation

procedure TGmConfig.SetDate(const Value: TDate);
begin
  FDate := Value;
end;

end.

以下是测试代码:
unit Unit1;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, ComCtrls, CnAOTreeView, CnAutoOption,  RzButton,GmConfig;

type
  TForm1 = class(TForm)
    CnAOTreeView1: TCnAOTreeView;
    RzBitBtn1: TRzBitBtn;
    procedure RzBitBtn1Click(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  Form1: TForm1;

implementation

{$R *.dfm}

procedure TForm1.RzBitBtn1Click(Sender: TObject);
var Option: TCnOptionGroup;
         gm:TGmConfig;
begin
  Option := TCnOptionGroup.Create(nil);
  gm:=TGmConfig.Create();
  gm.IntValue:=1;
  gm.Date:=Now;
  Option.Text := '自动参数设置演示程序';
  with Option.AddGroup('配置参数测试') do
  begin
    AddItem(gm,'intvalue','数据');
    AddItem(gm,'date','日期');

  end;

  CnAOTreeView1.Options := Option;
end;

end.

现在的问题是运行下划线的语句时就出现错误,不知什么原因?请高手多多指教!
Top
zjy
管理员
Rank: 9Rank: 9Rank: 9



UID 2
Digest Posts 6
Credits 2385
Posts 1543
点点分 2385
Reading Access 102
Registered 2002-12-16
Location China
Status Offline
Post at 2009-2-19 19:39  Profile | Site | Blog | P.M. 
请查看 Demo 的用法

Demo 在 cnpack\Examples\AutoOption 下面。

划线代码出错是因为 AutoOption 是通过 RTTI 来读写属性的,您需要:
1、从 TObject 派生来的 TGmConfig 默认是不带 RTTI 属性的,解决的办法一是从 TPersistent 派生,二是在类声明前用 {$M+} 编译指令指定生成 RTTI。
2、将 IntValue 和 Date 属性声明为 published 属性。




Zhou JingYu
CnPack Administrator
http://www.cnpack.org/
Top
雨中雪
普通灌水员
Rank: 2



UID 41830
Digest Posts 0
Credits 79
Posts 29
点点分 79
Reading Access 10
Registered 2009-2-19
Status Offline
Post at 2009-2-20 12:29  Profile | Blog | P.M. 
type
  TGmConfig = class(TPersistent)
  private
   { Private declarations }
  public
    { Public declarations }
    FDate: TDate;
    FIntValue: Integer;

    procedure SetDate(const Value: TDate);
   
    property Date: TDate read FDate write SetDate;
    property IntValue: Integer read FIntValue write FIntValue;
  end;

按照您的说明,改了代码,为什么还不行

出现错误为:Invalid property define :TGmConfig.IntValue
Top
Passion (LiuXiao)
管理员
Rank: 9Rank: 9Rank: 9


UID 359
Digest Posts 19
Credits 6756
Posts 3554
点点分 6756
Reading Access 102
Registered 2004-3-28
Status Offline
Post at 2009-2-20 12:31  Profile | Blog | P.M. 
published
Top
雨中雪
普通灌水员
Rank: 2



UID 41830
Digest Posts 0
Credits 79
Posts 29
点点分 79
Reading Access 10
Registered 2009-2-19
Status Offline
Post at 2009-2-20 12:36  Profile | Blog | P.M. 
感谢,问题已解决
Top
 




All times are GMT++8, the time now is 2024-4-20 14:45

    本论坛支付平台由支付宝提供
携手打造安全诚信的交易社区 Powered by Discuz! 5.0.0  © 2001-2006 Comsenz Inc.
Processed in 0.008051 second(s), 7 queries , Gzip enabled

Clear Cookies - Contact Us - CnPack Website - Archiver - WAP