哦,和客户端程序的保存位置没有关系?!那就是说我只要在客户端都加入对COM服务器中SortInterface的引用就ok了?
是不是建立了客户端应用程序一切正常就可以实现了?
我的ProjectManager下的目录为:
ProjectGroup1
SortServ.dll
Client
Client.pas
Form1
SortInterface.pas
SortServ_TLB.pas
Unit1.pas
你看看有问题吗??
另外,SortServ.dpr源码为:
[red]library SortServ;
uses
ComServ,
Unit1 in 'Unit1.pas',
SortInterface in 'SortInterface.pas',
SortServ_TLB in 'SortServ_TLB.pas',
Client in 'Client.pas' {Form1};
exports
DllGetClassObject,
DllCanUnloadNow,
DllRegisterServer,
DllUnregisterServer;
{$R *.TLB}
{$R *.RES}
begin
end.[/red]
SortInterface源码为:
[red]unit SortInterface;
interface
type
IMySort = interface
['{B0068395-92B6-4534-99A0-2E7B48E2D05F}']
procedure SetValue(iVal:Integer);
function GetSize:Integer;
function GetVal(iInd:Integer):Integer;
procedure BeginSort;
procedure ClearStack;
end;
const
Class_IMySort:TGUID='{B0068395-92B6-4534-99A0-2E7B48E2D05F}';
implementation
end.[/red]
Unit1源码为:
[red]unit Unit1;
interface
uses
Windows, ActiveX, Classes, ComObj,SortInterface;
type
TMySort = class(TComObject,IMySort)
protected
FItems:array[0..19]of integer;
FPoint:Integer;
Public
constructor Create;
procedure SetValue(iVal:Integer);
function GetSize:Integer;
function GetVal(iInd:Integer):Integer;
procedure BeginSort;
procedure ClearStack;
end;
implementation
uses ComServ;
constructor TMySort.Create;
begin
//建立类时将FPoint设置为0
FPoint:=0;
end;
procedure TMySort.ClearStack;
begin
FPoint:=0;
end;
procedure TMySort.SetValue(iVal:Integer);
begin
//将新数值添加到数组中
if FPoint<20 then begin
FItems[FPoint]:=iVal;
FPoint:=FPoint+1;
end;
end;
function TMySort.GetSize:Integer;
begin
//返回数组中数值的个数
Result:=FPoint;
end;
function TMySort.GetVal(iInd:Integer):Integer;
begin
//返回数组中各个数值
if((iInd>=0)and(iInd<=FPoint))then
Result:=FItems[iInd]
else
Result:=0;
end;
procedure TMySort.BeginSort;
var
i,j,Temp:Integer;
begin
//利用简单的冒泡法对数组进行排序
for i:=0 to FPoint do
for j:=FPoint downto i+1 do begin
if FItems[j]<FItems[j-1] then begin
Temp:=FItems[j];
FItems[j]:=FItems[j-1];
FItems[j-1]:=Temp;
end;
end;
end;
initialization
TComObjectFactory.Create(ComServer,TMySort,class_IMySort,'MySort','',
ciMultiInstance,tmApartment);
end.[/red]
Client.pas源码为:
[red]unit Client;
interface
uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
SortInterface,ComObj,ComCtrls,StdCtrls;
type
TForm1 = class(TForm)
btnAdd: TButton;
btSort: TButton;
btnClear: TButton;
ListBox1: TListBox;
Label1: TLabel;
procedure btnAddClick(Sender:TObject);
procedure FormCreate(Sender:TObject);
procedure btnClearClick(Sender:TObject);
procedure btSortClick(Sender:TObject);
private
FSort:IMySort;
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
{$R *.DFM}
procedure TForm1.btnAddClick(Sender:TObject);
var
xc:Integer;
begin
Randomize;
xc:=Random(1000);
FSort.SetValue(xc);
ListBox1.Items.Add(IntToStr(Xc));
Label1.Caption:=IntToStr(FSort.GetSize);
end;
procedure TForm1.FormCreate(Sender:TObject);
begin
FSort:=CreateComObject(class_IMySort)as IMySort;
end;
procedure TForm1.btnClearClick(Sender:TObject);
begin
FSort.ClearStack;
ListBox1.Clear;
end;
procedure TForm1.btSortClick(Sender:TObject);
var
i:Integer;
begin
FSort.BeginSort;
ListBox1.Clear;
for i:=0 to FSort.GetSize -1 do
ListBox1.Items.Add(IntToStr(FSort.GetVal(i)));
end;
end.[/red]
麻烦你给看看!!还有,我原来建立的ClientPrj.dpr文件找不到了,呵呵,好像被我修改保存了!!
其源码是:
program ClientPrj;
uses
Forms,
Client in 'Client.pas'{Form1},
SortInterface in '../SortInterface.pas';
{$R *.RES}
begin
Application.Initialize;
Application.CreateForm(TForm1,Form1);
Application.Run;
end.
真的很是麻烦了,小弟我也研究研究,回来再讨教!!!
感谢!!!!