易截截图软件、单文件、免安装、纯绿色、仅160KB

《Delphi 算法与数据结构》: 数据对齐

为了加快硬件的访问速度, 编译器通常要使用"数据对齐", 譬如:
//下面结构中: SizeOf(TRec) = 6; 因为 b 在这里也要占 2 字节.
TRec = record
a: Word;
b: Byte;
c: Word;
end
;
//下面结构中: SizeOf(TRec) = 16; 这里的 a 和 b 共占了 8 个字节.
TRec = record
a: Byte;
b: Byte;
c: Double;
end
;
//下面结构中: SizeOf(TRec) = 8; 这里的 a 和 b 共占了 4 个字节.
TRec = record
a: Byte;
b: Byte;
c: Integer;
end
;
//下例使用了结构压缩(压缩后就对不齐了), 它们的大小会分别是: 2、1、8 字节
TRec = packed
record
a: Word;
b: Byte;
c: Double;
end
;
下面是一个测试:
unit
Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls;
type
TForm1 = class
(TForm)
Memo1: TMemo;
procedure
FormCreate(Sender: TObject);
end
;
var
Form1: TForm1;
implementation
{$R *.dfm}
type
rec1 = record
x: Integer;
y: Integer;
z: Integer;
end
;
rec2 = record
x: Integer;
y: Byte;
z: Integer;
end
;
rec3 = packed
record
x: Integer;
y: Byte;
z: Integer;
end
;
procedure
TForm1.FormCreate(Sender: TObject);
const
DashLine = '----------------------------------'
;
var
r1: rec1;
r2: rec2;
r3: rec3;
begin
Memo1.Align := alClient;
Memo1.Clear;
Memo1.Lines.Add(Format('rec1 结构的大小是: %d'
, [SizeOf(rec1)]));
Memo1.Lines.Add(Format('rec2 结构的大小是: %d'
, [SizeOf(rec2)]));
Memo1.Lines.Add(Format('rec3 结构的大小是: %d'
, [SizeOf(rec3)]));
Memo1.Lines.Add(DashLine);
Memo1.Lines.Add(Format('r1 中 x 的地址是: %d'
, [Integer(@r1.x)]));
Memo1.Lines.Add(Format('r1 中 y 的地址是: %d'
, [Integer(@r1.y)]));
Memo1.Lines.Add(Format('r1 中 z 的地址是: %d'
, [Integer(@r1.z)]));
Memo1.Lines.Add(DashLine);
Memo1.Lines.Add(Format('r2 中 x 的地址是: %d'
, [Integer(@r2.x)]));
Memo1.Lines.Add(Format('r2 中 y 的地址是: %d'
, [Integer(@r2.y)]));
Memo1.Lines.Add(Format('


相关文档:

Delphi播放Gif和Flash动画的方法


显示一个GIF动画
procedure ShowGIF( GIFFileName : String );
var TargetFrameName,PostData,Heads,Flags : OleVariant; URL : widestring; begin TargetFrameName := '';{指定Frame的空字符串时,则在当前Frame中打开动画文件} PostData := false;{不发送数据} Heads := '';{Header信息为空} Flags := 0;{Flags设为0} ......

DELPHI 实现内存修改的方法


注意:本文仅供技术交流,请勿用于非法用途。
要修改指定程序的指定地址数据,我们需要用到两个api函数,分别是ReadProcessMemory和WriteProcessMemory。
下载是函数的定义:
ReadProcessMemory
Reads data from an area of memory in a specified process. The entire area to be read must be accessible or the op ......

delphi 金山词霸屏幕取词技术的介绍

朋友,先要导入 XDICTGRB_TLB ,然后用下面的source,注意TForm1 = class(TForm,IXDictGrabSink) //!!!
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls, OleServer, XDICTGRB_TLB;
type
TForm1 = class(TForm,IXDictGrabSink) //!!!
GrabPro ......

delphi数据库处理


第一节 BDE、ADO、InterBase和dbExpress
    Delphi中处理数据库主要有两种方法,也就是BDE、ADO,从Delphi 6.0开始还加入了一种dbExpress方法。 另外,Delphi还提供了专门处理Borland 公司自己的数据库产品InterBase 数据库的专门的方法。
    BDE(Borland Databas Engine), 是Delph ......

DELPHI如何使用指针?

  DELPHI如何使用指针?
大家都认为,C语言之所以强大,以及其自由性,很大部分体
现在其灵活的指针运用上。因此,说指针是C语言的灵魂,一点都不为过。同时,这种说法也让很多人产生误解,似乎只有C语言的指针才能算指针。Basic不
支持指针,在此不论。其实,Pascal语言本身也是支持指针的。从最初的Pasca ......
© 2009 ej38.com All Rights Reserved. 关于E健网联系我们 | 站点地图 | 赣ICP备09004571号