今天看了《VCL》一章,感受很多,一般都学习JAVA的,对于面向对象用另外一个思维去解释的时候就显得有点不可以去适应了。
看了一下下午也只看了一个叫VMT的东西,虚拟方法表。明白了一个virtual与dynamic方法的区别。
相对来说,virtual占用的内存会很大比较多,每个子类都会把父类的的方法都列出来;对于dynamic就不会这样做的了,它只会把子类覆盖的放在VMT表中,其它的它会往上面找父类的方法。这个为VCL节省了很多内存。效率相对于virtual是相对慢了一点,可是节省了50%的空间,才拖延了3%的时间,很好的时间换空间的例子。
内存的逻辑结构为:
实验代码:
unit fmMain; interface uses Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms, Dialogs, Buttons, ComCtrls, DB, DBTables, StdCtrls, ExtCtrls; type TForm1 = class(TForm) Button1: TButton; CheckBox1: TCheckBox; RadioButton1: TRadioButton; ListBox1: TListBox; Memo1: TMemo; Button2: TButton; Button3: TButton; Database1: TDatabase; PageControl1: TPageControl; TabSheet1: TTabSheet; TabSheet2: TTabSheet; lbVMTs: TListBox; lbVMTContents: TListBox; BitBtn1: TBitBtn; BitBtn2: TBitBtn; Button4: TButton; Button5: TButton; procedure Button1Click(Sender: TObject); procedure CheckBox1Click(Sender: TObject); procedure RadioButton1Click(Sender: TObject); procedure ListBox1Click(Sender: TObject); procedure Button2Click(Sender: TObject); procedure Memo1Click(Sender: TObject); procedure Button3Click(Sender: TObject); procedure BitBtn1Click(Sender: TObject); procedure Button4Click(Sender: TObject); procedure Button5Click(Sender: TObject); private { Private declarations } aClass : TClass; sClassName : String; procedure ShowVMTResult(const Msg: string); procedure ShowVMTEntry(const iDelta: Integer; pVMT: Pointer); procedure ShowVMTContent(aVMT: TClass); public { Public declarations } end; var Form1: TForm1; implementation {$R *.dfm} procedure TForm1.Button1Click(Sender: TObject); begin aClass := Self.Button1.ClassType; sClassName := 'TButton'; end; procedure TForm1.CheckBox1Click(Sender: TObject); begin aClass := Self.CheckBox1.ClassType; sClassName := 'TCheckBox'; end; procedure TForm1.RadioButton1Click(Sender: TObject); begin aClass := Self.RadioButton1.ClassType; sClassName := 'TRadioButton'; end; procedure TForm1.ListBox1Click(Sender: TObject); begin aClass := Self.ListBox1.ClassType; sClassName := 'TListBox'; end; procedure TForm1.Button2Click(Sender: TObject); begin aClass := Self.ClassType; sClassName := 'TForm1'; end; procedure TForm1.Memo1Click(Sender: TObject); begin aClass := Self.Memo1.ClassType; sClassName := 'TMemo'; end; procedure TForm1.Button3Click(Sender: TObject); begin aClass := Self.Database1.ClassType; sClassName := 'TDatabase'; end; procedure TForm1.BitBtn1Click(Sender: TObject); begin ShowVMTContent(aClass); end; const VMTOFFSET = 12; VMTDELTA = 4; procedure TForm1.ShowVMTContent(aVMT: TClass); var pVMT : Pointer; idx : Integer; begin ShowVMTResult(sClassName + ' VMT表格地址 : ' + IntToStr(Integer(aVMT)) ); pVMT := Pointer(aVMT); idx := VMTOFFSET; while (idx > vmtSelfPtr) do begin ShowVMTEntry(idx, pVMT); Dec(idx, VMTDELTA); end; // while end; procedure TForm1.ShowVMTEntry(const iDelta: Integer; pVMT: Pointer); var pResult : Pointer; Msg : String; procedure DoProcess(const sName : String); begin if (Assigned(pResult)) then begin Msg := Format('%s : %x', [sName, Integer(pResult)]); ShowVMTResult(Msg); end; end; begin pResult := Pointer(Integer(pVMT) + iDelta); case iDelta of // vmtCreateObject : DoProcess('vmtCreateObject'); vmtRelease : DoProcess('vmtRelease'); vmtAddRef : DoProcess('vmtAddRef'); vmtQueryInterface : DoProcess('vmtQueryInterface'); vmtDestroy : DoProcess('vmtDestroy'); vmtFreeInstance : DoProcess('vmtFreeInstance'); vmtNewInstance : DoProcess('vmtNewInstance'); vmtDefaultHandler : DoProcess('vmtDefaultHandler'); vmtDispatch : DoProcess('vmtDispatch'); vmtBeforeDestruction : DoProcess('vmtBeforeDestruction'); vmtAfterConstruction : DoProcess('vmtAfterConstruction'); vmtSafeCallException : DoProcess('vmtSafeCallException'); vmtParent : DoProcess('vmtParent'); vmtInstanceSize : DoProcess('vmtInstanceSize'); vmtClassName : DoProcess('vmtClassName'); vmtDynamicTable : DoProcess('vmtDynamicTable'); vmtMethodTable : DoProcess('vmtMethodTable'); vmtFieldTable : DoProcess('vmtFieldTable'); vmtTypeInfo : DoProcess('vmtTypeInfo'); vmtInitTable : DoProcess('vmtInitTable'); vmtAutoTable : DoProcess('vmtAutoTable'); vmtIntfTable : DoProcess('vmtIntfTable'); vmtSelfPtr : DoProcess('vmtSelfPtr'); end; // case end; procedure TForm1.ShowVMTResult(const Msg: string); begin Self.lbVMTs.Items.Add(Msg); end; procedure TForm1.Button4Click(Sender: TObject); var aPnl : TPanel; aForm : TForm1; begin aClass := aPnl.ClassType; sClassName := 'TPanel'; ShowVMTContent(aClass); aPnl := TPanel.Create(Self); aClass := aPnl.ClassType; sClassName := 'TPanel'; ShowVMTContent(aClass); FreeAndNil(aPnl); end; procedure TForm1.Button5Click(Sender: TObject); var Msg : String; pVMT : Pointer; begin Msg := Format('%s : %x', ['Self', Integer(Pointer(Self))]); ShowVMTResult(Msg); pVMT := Pointer(Integer(Pointer(Self)^) + vmtSelfPtr); Msg := Format('%s : %x', ['vmtSelfPtr', Integer(Pointer(pVMT))]); ShowVMTResult(Msg); pVMT := Pointer(Pointer(Integer(Pointer(Self)^) + vmtSelfPtr)^); Msg := Format('%s : %x', ['vmtSelfPtr', Integer(Pointer(pVMT))]); ShowVMTResult(Msg); end; end.
显示实验为:
相关推荐
Object Pascal 编程语言手册-Delphi 11 Alexandria,Object Pascal 编程语言手册-Delphi 11 Alexandria,Object Pascal 编程语言手册-Delphi 11 Alexandria
Self-Correction-Human-Parsing SCHP models exp-schp-201908270938-pascal-person-part.pth
奥教案(PASCAL)-2019-11-19
Free Pascal 3.0.4 Windows 32-bit 绿色版,解压即用,方便快捷。 Free Pascal is a 32, 64 and 16 bit professional Pascal compiler. It can target many processor architectures: Intel x86 (including 8086), ...
RemObjects Pascal Script for Delphi - 3.0.75.1117
NWPU VHR-10的pascal voc格式NWPU VHR-10的pascal voc格式NWPU VHR-10的pascal voc格式NWPU VHR-10的pascal voc格式NWPU VHR-10的pascal voc格式NWPU VHR-10的pascal voc格式NWPU VHR-10的pascal voc格式NWPU VHR-10...
Graphonomy Pascal-Person-Part trained model, https://github.com/Gaoyiminggithub/Graphonomy
超强大、好用的Pascal语言解释器:RemObjects Pascal Script,支持D7-XE8
DOSpascal.rar 很古老了,但很经典很实用,我为了学编程特意去买了个PPC...用来写PASCAL程序还是不错的,可以开发WIN32程序和DOS程序,当然你得有这个水平才行。刀是好刀,看你怎么用了。积分!积分!我要积分!^_^
安卓上的免费Pascal语言编译器,也支持基本的面向对象功能(可以使用class),可以供大家玩玩。
Delphi历史版本详解-从-Turbo-Pascal-到-Delphi-XE-2
显著性检测数据集PASCAL-S,850张GT&850张image
Pascal-Person-Part:人体解析语义分割数据集,只有6种不同的语义标签,与人相关的也较粗糙,图像总数3553。
一款免费的用Delphi编写的脚本引擎,允许你在程序运行时使用Object Pascal语言,是一套能够编译到exe文件的单元,使用脚本引擎的好处:能够让你的程序让用户的自定义而不需要重新编译,你能够发布升级程序只需要发布...
这是来自苏黎世的 Pascal-P 编译器的第 5 版。 这是修改为 ISO 7185 Pascal 编译器的 Pascal-P4 编译器,无论是在实现语言中,还是在它处理的语言中。 Pascal-P 是一个实现工具包,创建于 1972 年和 1974 年之间,...
《DirectX 9.0 3D游戏开发编程基础》源码Pascal版 ------------------------ 编译前设置 ( Delphi7 ) 1.File -> Close All 2.Project -> Options -> Directories/Conditionals -> Search Path 3.Add: DirectX_...
第一章 初识pascal 语言 ………1 第二章 简单程序设计 第一节 数据类型、常量、变量…………4 第二节 赋值语句 …………7 第三节 输出语句(WRITE 语句)………8 第四节 输入语句(READ 语句) ………9 第五节 顺序结构...
这是苏黎世联邦理工学院 Niklaus Wirth 的原始 Pascal-S 项目。 它一步编译和解释 Pascal 语言的一个子集,并且只用了大约 2000 行。 您可以在 sourceforge 中找到所有 Pascal-P 版本:...
triangulo-de-pascal-cpp-源码.rar