以microsoft.sqlserver.types.dll为例探讨下D7中运用.net组件的可能性。
ModelMaker 可以导入.net Assembly文件,形成一个类声明,未包含属性与域成员。
以下代码号称可以引用:
uses Variants, COMOBJ, OleCtnrs, Activex;
procedure TForm1.Button1Click(Sender: TObject);
var
SharpObject: Variant; //olevariant
TestValue: string;
begin
try
try
SharpObject := CreateOleObject('CSharpServer.SharpObject');
TestValue := SharpObject.DecryptTripleDES(Edit1.Text);
Edit2.Text :=TestValue;
except
on e: exception do
begin
ShowMessage(e.Message);
end;
end;
finally
SharpObject := Unassigned;
end;
end;
procedure TForm1.Button2Click(Sender: TObject);
var
SharpObject: Variant;
TestValue: string;
begin
try
try
SharpObject := CreateOleObject('CSharpServer.SharpObject');
TestValue := SharpObject.EncryptTripleDES(Edit2.Text);
Edit1.Text :=TestValue;
except
on e: exception do
begin
ShowMessage(e.Message);
end;
end;
finally
SharpObject := Unassigned;
end;
end;
initialization
CoInitialize(nil);
finalization
CoUninitialize;
end.