如题,需要哪几个步骤啊,没有头绪,一般的书上都避而不谈

解决方案 »

  1.   

    这是我以前练习的一个源码!
    unit treecode;interfaceuses
      Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
      Dialogs, StdCtrls, Buttons,  ADODB, ImgList, ComCtrls, DBTables, DB,
      WinSkinData;type
      TForm1 = class(TForm)
        TVcode: TTreeView;
        ImageList1: TImageList;
        BitBtn1: TBitBtn;
        ADOtbl: TADOTable;
        SkinData1: TSkinData;
        BitBtn2: TBitBtn;    procedure BitBtn1Click(Sender: TObject);
        procedure FormCreate(Sender: TObject);
        procedure BitBtn2Click(Sender: TObject);
      private
        { Private declarations }
        function LoadCode(crTbl:TadoTable):Integer;
        function GetLevel(sFormat,sCode:String):Integer;
      public
        { Public declarations }
      end;var
      Form1: TForm1;
    const
      SCodeFormat ='322222'; //科目代码结构
      SFirstNodeTxt ='科目代码'; //首节点显示的文字
    implementationuses about;{$R *.dfm}
    procedure TForm1.BitBtn1Click(Sender: TObject);
    begin
    close;
    end;procedure TForm1.FormCreate(Sender: TObject);
    begin
    adotbl.indexfieldnames:='acode';
    loadcode(adotbl);
    end;function Tform1.LoadCode(crTbl:TadoTable):Integer;
    var
    newid,showTxt:string;
    level:integer;
    MyNode:array[0..6]of TTreeNode;//保存各级节点,最长支持6级(重点)
    begin
      Screen.Cursor:=crHourGlass;
      level:=0;
      with crTbl do
      begin
        try
          if not active then
          open;
          first;
          tvcode.Items.Clear;
          //以下增加第一项
          mynode[level]:=tvcode.Items.Add(tvcode.TopItem,SFirstNodeTxt);
          mynode[level].ImageIndex:=0;
          mynode[level].SelectedIndex:=0;
          //以上是增加第一项
          while not eof do
          begin
            newid:=trim(fieldbyname('acode').AsString);
            ShowTxt:=NewID+''+FieldByName('aName').AsString;
            level:=getlevel(SCodeFormat,newid);//返回代码的级数
            //以下是增加子项
            //以下用上一级节点为父节点添加子节点
            if level>0 then //确保代码符合标准
              begin
              mynode[level]:=tvcode.Items.AddChild(mynode[level-1],showtxt);
              mynode[level].ImageIndex:=1;
              mynode[level].SelectedIndex:=2;
              end;
            next;
           end;
         finally
          close;
         end;
       end;
     mynode[0].Expand(false);//将首节点展开
     Screen.Cursor:=crDefault;
     end;function Tform1.GetLevel(sFormat,sCode:String):Integer;
    var
    i,level,ilen:integer;
    begin
    level:=-1;
    ilen:=0;
    if (sFormat<>'') and (sCode<>'') then
      begin
      for i:=1 to length(sFormat) do
      begin
        ilen:=ilen+strtoint(sFormat[i]);
        if length(sCode)=ilen then
          begin
          level:=i;
          break;
          end;
      end;
    end;
    result:=level;
    end;
    procedure TForm1.BitBtn2Click(Sender: TObject);
    begin
    form2.ShowModal;
    end;end.
      

  2.   

    //参考如下代码,然后自己到TypInfo.pas里看看所声明的函数~~
    uses TypInfo;procedure TForm1.Button1Click(Sender: TObject);
    begin
      SetStrProp(Self, 'Caption', 'Hello');
      SetOrdProp(Self, 'Color', clRed);
      SetSetProp(Self, 'BorderIcons', '[biMinimize]');
    end;
      

  3.   

    呵呵...翻遍了VCL源码,却发现已经有很多现成的函数..在typinfo单元.比如
    uses typinfo;
    ...procedure TForm1.Button2Click(Sender: TObject);
    var
      a:Variant;
      PropName:String;
    begin
      PropName:=Edit1.Text;
      a:=GetPropValue(Button1,PropName);
      ShowMessage(a);end;
      

  4.   

    但我自己做一个类:
    TC = class
      private
        FCaption: String;
      public
        destructor Destroy; override;
        property Caption: String read FCaption write FCaption;
      end;
    这样就不行,是不是在用SetStrProp之前还需要对该属性进行类似于注册之类的操作?
    借此机会进一步问各位:要是我想通过字符串得到一个类的实例,并且访问他的方法,我该怎么做呢?
    通过字符串、指针访问一个过程或函数我该怎么做?
      

  5.   

    //RTTI针对的是published部分~~  TC = class
      private
        FCaption: String;
      public
        destructor Destroy; override;
      published
        property Caption: String read FCaption write FCaption;
      end;//Classes中的函数~~
    function GetClass(const AClassName: string): TPersistentClass;
    begin
      RegGroups.Lock;
      try
        Result := RegGroups.GetClass(AClassName);
      finally
        RegGroups.Unlock;
      end;
    end;function FindClass(const ClassName: string): TPersistentClass;
    begin
      Result := GetClass(ClassName);
      if Result = nil then ClassNotFound(ClassName);
    end;//自己去研究研究~~
    procedure RegisterClass(AClass: TPersistentClass);
    procedure RegisterClasses(AClasses: array of TPersistentClass);
    procedure UnRegisterClass(AClass: TPersistentClass);
    procedure UnRegisterClasses(AClasses: array of TPersistentClass);
      

  6.   

    还没搞定
    unit Unit1;interfaceuses
      Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
      Dialogs, StdCtrls, TypInfo;type
      TForm1 = class(TForm)
        Button1: TButton;
        procedure Button1Click(Sender: TObject);
      private
        { Private declarations }
      public
        { Public declarations }
      end;  TC = class
      private
        FCaption: String;
      public
        destructor Destroy; override;
      published
        property Caption: String read FCaption write FCaption;
      end;var
      Form1: TForm1;
      C: TC;implementation{$R *.dfm}destructor TC.Destroy;
    begin
      inherited Destroy;
    end;procedure TForm1.Button1Click(Sender: TObject);
    begin
      C := TC.Create;
      SetStrProp(C, 'Caption', 'AAA');
    end;initialization
      RegisterClass(TC);   //怎样使用RegisterClass?end.
      

  7.   

    HOHO,伴水?想泡第二个马甲?楼上的伴水和哈欠都给了你答案了,不过我感觉哈欠给的答案是你所想实现的功能!
      

  8.   

    RegisterClass(TC);
    这句编译不过,提示类型不匹配 TPersistentClass and Class reference
    我使用RegisterClass(TPersistentClass(TC));
    能编译过,但已运行就提示经典的访问无效地址搞不明白,还请高手指教,在线等,运行成功马上给分,先谢谢
      

  9.   

    对,通过RegisterClass函数进行注册的类必须是TPersistent派生下来的,如果你从TObject直接派生肯定是要出错的!把你代码里面的TC的申明写成这样就可以了:TC = class(TPersistent)
      private
        FCaption: String;
      public
        destructor Destroy; override;
      published
        property Caption: String read FCaption write FCaption;
      end;
      

  10.   

    Type Switch
    Syntax {$M+} or {$M-}
    {$TYPEINFO ON} or {$TYPEINFO OFF}
    Default {$M-}
    {$TYPEINFO OFF}
    Scope Local
    The $M switch directive controls generation of runtime type information (RTTI). When a class is declared in the {$M+} state, or is derived from a class that was declared in the {$M+} state, the compiler generates runtime type information for fields, methods, and properties that are declared in a published section. If a class is declared in the {$M-} state, and is not derived from a class that was declared in the {$M+} state, published sections are not allowed in the class. Note that if a class is forward declared, the first declaration of the class must be declared with the $M switch.Note: The TPersistent class defined in the Classes unit of the VCL and CLX is declared in the {$M+} state, so any class derived from TPersistent will have RTTI generated for its published sections. The VCL/CLX uses the runtime type information generated for published sections to access the values of a component's properties when saving or loading form files. Furthermore, the IDE uses a component's runtime type information to determine the list of properties to show in the Object Inspector.There is seldom, if ever, any need for an application to directly use the $M compiler switch.//....{$M+}
      TC = class
      private
        FCaption: String;
      public
        destructor Destroy; override;
      published
        property Caption: String read FCaption write FCaption;
      end;
    {$M-}var
      Form1: TForm1;
      C: TC;implementation{$R *.dfm}destructor TC.Destroy;
    begin
      inherited Destroy;
    end;procedure TForm1.Button1Click(Sender: TObject);
    begin
      C := TC.Create;
      SetStrProp(C, 'Caption', 'AAA');
    end;//....
      

  11.   

    给不给都无所谓了~~
    大家又不是为蹭这点分来的~~
    要是你闲麻烦就把分全部给俺吧~~
    他们不会说什么的~~嘿嘿!(左手捂住FrameSniper的嘴,右手捂住halfdream的嘴)