program ListCli;
uses
Forms,
LCliForm in 'LCliForm.pas' ,
ListServ_TLB in 'ListServ_TLB.pas';
begin
Application.Initialize;
Application.CreateForm(TListCliForm, ListCliForm);
Application.Run;
end.
|
unit LCliForm;
interface
uses
Windows, Messages, SysUtils, Classes, Graphics, Controls,
Forms, Dialogs, StdCtrls, ListServ_TLB;
type
TListCliForm = class(TForm)
btnFont: TButton;
FontDialog1: TFontDialog;
btnMemList: TButton;
EditItem: TEdit;
btnMemoTo: TButton;
Memo1: TMemo;
btnAdd: TButton;
btnServer: TButton;
procedure btnFontClick(Sender: TObject);
procedure btnMemListClick(Sender: TObject);
procedure btnMemoToClick(Sender: TObject);
procedure btnAddClick(Sender: TObject);
procedure btnServerClick(Sender: TObject);
private
fInternalListServ: IListServer;
function GetListSrv: IListServer;
public
property ListSrv: IListServer
read GetListSrv;
end;
var
ListCliForm: TListCliForm;
implementation
uses
ActiveX, AxCtrls, StdVCL;
procedure TListCliForm.btnFontClick(Sender: TObject);
var
NewFont: IFontDisp;
begin
if FontDialog1.Execute then
begin
GetOleFont (FontDialog1.Font, NewFont);
ListSrv.Font := NewFont;
end;
end;
procedure TListCliForm.btnMemListClick(Sender: TObject);
var
TempIStrs: IStrings;
List: TStrings;
I: Integer;
begin
List := TStringList.Create;
try
for I := 1 to 10 do
List.Add ('Item ' + IntToStr (I));
GetOleStrings (List, TempIStrs);
ListSrv.Items := TempIStrs;
finally
List.Free;
end;
end;
procedure TListCliForm.btnMemoToClick(Sender: TObject);
var
TempIStrs: IStrings;
begin
GetOleStrings (Memo1.Lines, TempIStrs);
ListSrv.Items := TempIStrs;
end;
procedure TListCliForm.btnAddClick(Sender: TObject);
var
TempIStrs: IStrings;
List: TStrings;
begin
List := TStringList.Create;
try
TempIStrs := ListSrv.Items;
TempIStrs.Add (EditItem.Text);
SetOleStrings (List, TempIStrs);
GetOleStrings (List, TempIStrs);
ListSrv.Items := TempIStrs;
finally
List.Free;
end;
end;
procedure TListCliForm.btnServerClick(Sender: TObject);
var
TempIStrs: IStrings;
begin
TempIStrs := ListSrv.Items;
SetOleStrings (Memo1.Lines, TempIStrs);
end;
function TListCliForm.GetListSrv: IListServer;
begin
if not Assigned (fInternalListServ) then
fInternalListServ := CoCoListServ.Create;
Result := fInternalListServ;
end;
end.
|
unit ListServ_TLB;
interface
uses ActiveX, Classes, Graphics, OleServer, StdVcl, Variants, Windows;
const
ListServMajorVersion = 1;
ListServMinorVersion = 0;
LIBID_ListServ: TGUID = '{3BDFE8EA-CA1A-4918-8643-8F8D5EE2371E}';
IID_IListServer: TGUID = '{DD9E3D16-E878-4ECC-9F1D-CDEE4B2C3B02}';
CLASS_CoListServ: TGUID = '{4D54A7F2-9D93-469A-BEB9-F8C8F25F3408}';
type
IListServer = interface;
IListServerDisp = dispinterface;
CoListServ = IListServer;
IListServer = interface(IDispatch)
['{DD9E3D16-E878-4ECC-9F1D-CDEE4B2C3B02}']
function Get_Items: IStrings; safecall;
procedure Set_Items(const Value: IStrings); safecall;
function Get_Font: IFontDisp; safecall;
procedure Set_Font(const Value: IFontDisp); safecall;
property Items: IStrings read Get_Items write Set_Items;
property Font: IFontDisp read Get_Font write Set_Font;
end;
IListServerDisp = dispinterface
['{DD9E3D16-E878-4ECC-9F1D-CDEE4B2C3B02}']
property Items: IStrings dispid 1;
property Font: IFontDisp dispid 2;
end;
CoCoListServ = class
class function Create: IListServer;
class function CreateRemote(const MachineName: string): IListServer;
end;
implementation
uses ComObj;
class function CoCoListServ.Create: IListServer;
begin
Result := CreateComObject(CLASS_CoListServ) as IListServer;
end;
class function CoCoListServ.CreateRemote(const MachineName: string): IListServer;
begin
Result := CreateRemoteComObject(MachineName, CLASS_CoListServ) as IListServer;
end;
end.
|