如何使用变量替代自定义Record的属性?(50)

3

336764

Unregistered / Unconfirmed
GUEST, unregistred user!
请问,我定义了一个Record如:TSet=record a:string
b:string;end;MySet:TSet;请问,我怎么用变量替代a和b?实现类似:MySet.a:='text';(MySet.变量:='text')这样的目的?谢谢。
 
这样行不行TSet=class //更改为类 a:string
b:string
变量: string set()方法对a赋值;end;在pas的初始化段实例化,结束时释放还不行的话,替换吧
 
变量: string set()方法对a赋值;什么意思?谢谢。
 
可以给属性指定 属性set和read 方法TSet=class //更改为类 a:string
b:string
Property Var: string read a write SetVar;end;Procedure TSet.SetVar(value:string);Begin a:=value;End;
 
我是想知道:TSet=class a:string;end;////////str:='a';setStrProp(MySet, str, str);类似这种,但是我在d2007中这么写,就会出现 没有a这个属性的提示。
 
最后干脆写了一个变量控件来解决这个问题。。虽然麻烦点,但是能解决问题。谢谢。
代码:
unit SetVar;interfaceuses  Windows, Messages, Classes, Forms;type  TSetVar = class(TComponent)  private    Fabc: String
   Fdef: String
   procedure SetabcStr(Value: String)
   procedure SetdefStr(Value: String)
 protected  public    constructor Create(AOwner: TComponent)
override
   destructor Destroy
override
 published    property abc: String read Fabc write SetabcStr
   property def: String read Fdef write SetdefStr
 end;procedure Register;implementationconstructor TSetVar.Create(AOwner: TComponent);begin  inherited Create(AOwner);end;destructor TSetVar.Destroy;begin  inherited Destroy;end;procedure TSetVar.SetabcStr(Value: String);begin    Fabc:=Value;end;procedure TSetVar.SetdefStr(Value: String);begin    Fdef:=Value;end;procedure Register;begin  RegisterComponents('MySetVar', [TSetVar]);end;end.
代码:
unit Unit1;interfaceuses  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,  Dialogs, StdCtrls, SetVar, Typinfo;type  TForm1 = class(TForm)    SetVar1: TSetVar
   Button1: TButton
   procedure Button1Click(Sender: TObject)
 private    { Private declarations }  public    { Public declarations }  end;var  Form1: TForm1;implementation{$R *.dfm}procedure TForm1.Button1Click(Sender: TObject);var  str:String;begin    Str:='abc'
   SetPropValue(SetVar1, Str, Str)
   Showmessage(SetVar1.abc);end;end.
 
顶部