OLE клиент-сервер – Массив байт
Автор: Xavier Pacheco
unit CliMain;
interface
uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
StdCtrls, ExtCtrls, Server_TLB;
type
TMainForm = class(TForm)
Memo: TMemo;
Panel1: TPanel;
SetButton: TButton;
GetButton: TButton;
OpenButton: TButton;
OpenDialog: TOpenDialog;
procedure OpenButtonClick(Sender: TObject);
procedure FormCreate(Sender: TObject);
procedure SetButtonClick(Sender: TObject);
procedure GetButtonClick(Sender: TObject);
private
FServer: IBinaryData;
end;
var
MainForm: TMainForm;
implementation
{$R *.DFM}
procedure TMainForm.FormCreate(Sender: TObject);
begin
FServer := CoBinaryData.Create;
end;
procedure TMainForm.OpenButtonClick(Sender: TObject);
begin
if OpenDialog.Execute then
Memo.Lines.LoadFromFile(OpenDialog.FileName);
end;
procedure TMainForm.SetButtonClick(Sender: TObject);
var
P: Pointer;
L: Integer;
V: OleVariant;
begin
// Send memo data to server
L := Length(Memo.Text);
V := VarArrayCreate([0, L - 1], varByte);
P := VarArrayLock(V);
try
Move(Memo.Text[1], P^, L);
finally
VarArrayUnlock(V);
end;
FServer.Data := V;
end;
procedure TMainForm.GetButtonClick(Sender: TObject);
var
P: Pointer;
L: Integer;
S: string;
V: OleVariant;
begin
// Get server's memo data
V := FServer.Data;
L := VarArrayHighBound(V, 1) - VarArrayLowBound(V, 1) + 1;
SetLength(S, L);
P := VarArrayLock(V);
try
Move(P^, S[1], L);
finally
VarArrayUnlock(V);
end;
Memo.Text := S;
end;
end.
Скачать весь проект
|