Delphi 之运算符重载
Delphi 7之后的版本,增加了运算符的重载。虽然不尽人意(需要写特定英文),但有总比没有强。
例:
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls;
type
T3DPoint = record
X, Y, Z: Double;
class operator ADD(ALeftPoint, ARightPoint: T3DPoint): T3DPoint; {重载'+'运算符}
end;
TForm1 = class(TForm)
Button1: TButton;
procedure Button1Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
{ T3DPoint }
class operator T3DPoint.ADD(ALeftPoint, ARightPoint: T3DPoint): T3DPoint;
begin
Result.X := ALeftPoint.X + ARightPoint.X;
Result.Y := ALeftPoint.Y + ARightPoint.Y;
Result.Z := ALeftPoint.Z + ARightPoint.Z;
end;
procedure TForm1.Button1Click(Sender: TObject);
var
A, B, Z: T3DPoint;
begin
A.X := 1; A.Y := 1; A.Z := 1;
B.X := 3; B.Y := 3; B.Z := 3;
Z := A + B;
ShowMessageFmt('%f, %f, %f', [Z.X, Z.Y, Z.Z]); {4.00, 4.00, 4.00}
//ShowMessage(FloatToStr(Z.X) + ',' + FloatToStr(Z.Y) + ',' + FloatToStr(Z.Z)); {4, 4, 4}
end;
end.
下面附上所有的运算符:
重载特定英文 行为(或目数) 方法 &nbs
相关文档:
研究了一下Pop3的邮件接收协议,然后随手写了一个Pop3的邮件接收控件!Pop3的邮件协议实际上是很简单的,知道那几个命令就行了,与服务器之间
的交互是一问一答得方式,控制起来也容易,相对而言邮件格式的解析倒是更加麻烦一点!于是也便顺带着将MIME邮件格式给熟悉了一下!总归说来,规律性比
较强,先获取最大的顶层框 ......
type
TCharStack = class(TStack)
private
function GetTop: Char;
public
function Pop: Char;
function Push(Item: Char): Char;
property Top: Char read GetTop;
end;
const
FindSet = ['(',')'];
implementation
{$R *.dfm}
{ TCharStack }
......
Procedure TForm1.Button1Click(Sender: TObject);
Var
xmlstr,FileName: String;
f: Textfile;
Begin
xmlStr := '<?xml version="1.0" encoding="gb2312"?>';
xmlstr := xmlstr + '<user><name>张三</name><sex>男</sex></user>';
sh ......
dll 调用方法有 静态调用和动态调用两种方法
用到的dll为上篇文章所编写的dll.
总结如下:
Unit Unit1;
Interface
Uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls;
Type
TForm1 = Class(TForm)
Button1: TButton; ......
delphi 注册 com 对象的方法
procedure TForm1.Button3Click(Sender: TObject);
var
Sd: TSecurityDescriptor;
begin
InitializeSecurityDescriptor(@Sd, SECURITY_DESCRIPTOR_REVISION);
SetSecurityDescriptorDacl(@Sd, true, Nil, false);
RegSe ......