我只是想学习变体记录,有人可以解释一下如何检查记录中的形状是矩形还是三角形等,或者有可用的实现示例吗?我在这里检查了变体记录,但是没有可用的实现。
type
TShapeList = (Rectangle, Triangle, Circle, Ellipse, Other);
TFigure = record
case TShapeList of
Rectangle: (Height, Width: Real);
Triangle: (Side1, Side2, Angle: Real);
Circle: (Radius: Real);
Ellipse, Other: ();
end;
Run Code Online (Sandbox Code Playgroud) 我试图在Delphi和PHP之间交换加密的消息.
从Delphi方面我从这里下载了DCPcrypt v2 Beta 3:
http://www.cityinthesky.co.uk/opensource/dcpcrypt/
对于加密我使用此功能:
function TForm1.Encrypt3DES(psData, psKey: string): string;
var
Cipher: TDCP_3des;
begin
Cipher:= TDCP_3des.Create(nil);
Cipher.InitStr(psKey,TDCP_sha256);
result:=Cipher.EncryptString(psData);
Cipher.Burn;
Cipher.Free;
end;
Run Code Online (Sandbox Code Playgroud)
我正在测试它:
ShowMessage(Encrypt3DES('test','SecretKeySecretKeySecret'));
Run Code Online (Sandbox Code Playgroud)
我得到的结果是Z74E0Q ==我可以使用另一个类似的delphi函数成功解密它:
function TForm1.Decrypt3DES(psData, psKey: string): string;
var
Cipher: TDCP_3des;
begin
Cipher:= TDCP_3des.Create(nil);
Cipher.InitStr(psKey, TDCP_sha256);
result:=Cipher.DecryptString(psData);
Cipher.Burn;
Cipher.Free;
end;
Run Code Online (Sandbox Code Playgroud)
从PHP端我试过几个功能相同的字符串("测试")使用相同的密钥("SecretKeySecretKeySecret")加密,但结果是什么,我在Delphi中得到不同的.我再次成功解密PHP中具有类似功能的消息,但我需要在Delphi中解密消息.
这是我在PHP中所做的,我甚至试图散列键,因为我看到Delphi函数正在使用TDCP_sha256,但结果仍然不同.
$key = "SecretKeySecretKeySecret";
echo base64_encode(mcrypt_encrypt(MCRYPT_3DES, $key, 'test', 'ecb')).'<BR><BR>';
echo openssl_encrypt('test', 'des-ede3', $key).'<BR><BR>';
$key = hash('sha256', $key);
echo openssl_encrypt('test', 'des-ede3', $key).'<BR><BR>';
Run Code Online (Sandbox Code Playgroud)
这是结果:
Z05z5Bp4/VY =
L5qmk5nJOzs =
bm7yRdrMs5g =
我究竟做错了什么?BTW我正在使用Delphi 7和DCPcrypt是目前唯一能够让它运行的库.
我试图从桌子上得到药物的价格,但我得到了:
procedure TForm1.BuyButtonClick(Sender: TObject);
var
iAmount : integer;
rRate : real;
sMedication : string;
sRate : string;
begin
iAmount := 0;
sMedication := BuyCombobox.Items[BuyCombobox.ItemIndex];
dmHospital.qryPrices.SQL.Clear;
dmHospital.qryPrices.SQL.Add('SELECT Price(R) FROM MedicationPrices WHERE Medication = quaotedstr(sMedication)');
sRate := dmHospital.qryPrices.SQL;
ShowMessage(sRate);
end;
Run Code Online (Sandbox Code Playgroud)