易截截图软件、单文件、免安装、纯绿色、仅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显示 jpg、png、gif 图片及 gif 动画的方法

unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls, ExtCtrls;
type
TForm1 = class(TForm)
    Button1: TButton;
    Button2: TButton;
    Button3: TButton;
    Bu ......

delphi随机输入验证码

输入验证码 一个文本框 24字母随机出4个字母 然后用户
输入所随机出的字母 输入正确 进入界面。。错误又随机下。。。
*/
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls;
type
TForm1 = class(TForm)
lbl1: TLabel;
Edit1: TEdit; ......

Delphi压缩图片代码

添加引用:uses JPEG;
//=====================图片处理函数,将覆盖原图片文件===========================
//=====filename:图片完整路径  PressQuality:压缩质量 Width:宽  Height:高
function CompressMainFun(filename: String; PressQuality,Width,Height:integer): Boolean;
var
  bmp: TBitmap ......

Delphi结束进程模块

uses Tlhelp32;
function KillTask(ExeFileName: string): integer;
const
  PROCESS_TERMINATE = $0001;
var
  ContinueLoop: BOOLean;
  FSnapshotHandle: THandle;
  FProcessEntry32: TProcessEntry32;
begin
  Result := 0;
  FSnapshotHandle := CreateToolhelp32Snapshot(T ......

DELPHI如何使用指针?

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