小
小花生
Unregistered / Unconfirmed
GUEST, unregistred user!
我相信重赏之下必有勇夫。
以下是原代码
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, MConnect, ObjBrkr, StdCtrls, Buttons,Registry;
type
a = POleVariant;
TForm1 = class(TForm)
BitBtn1: TBitBtn;
SimpleObjectBroker1: TSimpleObjectBroker;
BitBtn2: TBitBtn;
SimpleObjectBroker2: TSimpleObjectBroker;
procedure BitBtn1Click(Sender: TObject);
procedure BitBtn2Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
procedure TForm1.BitBtn1Click(Sender: TObject);
var
P : a
i: Integer;
begin
with TRegistry.Create do
try
if OpenKey('/Software/Borland/Delphi/Servers/', False) then
begin
i := ReadInteger('ServerInfoSize');
ShowMessage(IntToStr(i));
New(P);
try { read the state and restore SimpleObjectBroker1 }
ReadBinaryData('ServerInfo', P^, i);
SimpleObjectBroker2.ServerData := OleVariant(P^)
//这句话运行出错!!!
finally
FreeMem(P);
end;
end;
finally
Free;
end;
ShowMessage( SimpleObjectBroker2.Servers[0].ComputerName );
ShowMessage( SimpleObjectBroker2.Servers[1].ComputerName );
end;
procedure TForm1.BitBtn2Click(Sender: TObject);
var
i: Integer;
S1: String;
Ole1: a;
begin
with SimpleObjectBroker1 do
begin
for i:=0 to Servers.Count - 1 do
begin
if not Servers.HasFailed then {don抰 enable down servers }
begin
S1 := 'Do you want ' + Servers.ComputerName + ' enabled?';
if MessageBox(Handle, PChar(S1), PChar(Caption), MB_YESNO) = IDYES then
Servers.Enabled := True
else
Servers.Enabled := False;
end;
end;
New(Ole1);
Ole1^ := ServerData;
end;
{ save the ServerData to the registry for later use. }
with TRegistry.Create do
try
OpenKey('/Software/Borland/Delphi/Servers/', True);
WriteInteger('ServerInfoSize', SizeOf(Ole1^));
WriteBinaryData('ServerInfo', Ole1^, SizeOf(Ole1^));
finally
Free;
end;
ShowMessage(IntToStr(SizeOf(Ole1^)));
end;
end.
以下是原代码
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, MConnect, ObjBrkr, StdCtrls, Buttons,Registry;
type
a = POleVariant;
TForm1 = class(TForm)
BitBtn1: TBitBtn;
SimpleObjectBroker1: TSimpleObjectBroker;
BitBtn2: TBitBtn;
SimpleObjectBroker2: TSimpleObjectBroker;
procedure BitBtn1Click(Sender: TObject);
procedure BitBtn2Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
procedure TForm1.BitBtn1Click(Sender: TObject);
var
P : a
i: Integer;
begin
with TRegistry.Create do
try
if OpenKey('/Software/Borland/Delphi/Servers/', False) then
begin
i := ReadInteger('ServerInfoSize');
ShowMessage(IntToStr(i));
New(P);
try { read the state and restore SimpleObjectBroker1 }
ReadBinaryData('ServerInfo', P^, i);
SimpleObjectBroker2.ServerData := OleVariant(P^)
//这句话运行出错!!!
finally
FreeMem(P);
end;
end;
finally
Free;
end;
ShowMessage( SimpleObjectBroker2.Servers[0].ComputerName );
ShowMessage( SimpleObjectBroker2.Servers[1].ComputerName );
end;
procedure TForm1.BitBtn2Click(Sender: TObject);
var
i: Integer;
S1: String;
Ole1: a;
begin
with SimpleObjectBroker1 do
begin
for i:=0 to Servers.Count - 1 do
begin
if not Servers.HasFailed then {don抰 enable down servers }
begin
S1 := 'Do you want ' + Servers.ComputerName + ' enabled?';
if MessageBox(Handle, PChar(S1), PChar(Caption), MB_YESNO) = IDYES then
Servers.Enabled := True
else
Servers.Enabled := False;
end;
end;
New(Ole1);
Ole1^ := ServerData;
end;
{ save the ServerData to the registry for later use. }
with TRegistry.Create do
try
OpenKey('/Software/Borland/Delphi/Servers/', True);
WriteInteger('ServerInfoSize', SizeOf(Ole1^));
WriteBinaryData('ServerInfo', Ole1^, SizeOf(Ole1^));
finally
Free;
end;
ShowMessage(IntToStr(SizeOf(Ole1^)));
end;
end.