比较难的问题吧,求解。在线等...... 找金蝶财务软件多少钱
这个函数或过程在不在类中都可以,这样的代码应该怎么写?
不要告诉我用IF来判断,是不是应该用RTTI或接口什么的东西来实现?
先发100分,不够再加。
2楼: 将你需要调用的功能封装在DLL文件中,然后使用动态调用DLL技术即可达到你的目的 如金蝶财务软件多少钱
3楼: 这倒也是一种解决方案,不过我要是有100个函数就要写100个DLL吗?
这个程序要是放在服务器上运行,每执行一次就要调用一次DLL,那么多人来访问服务器受的了吗?
4楼: 大致是下面的样子,需要按名称调用的方法要声明为Published,比如
TForm1 = ...
published
function Test(aParam: Pointer): Boolean;
function TForm1.CallByName(const aName: String; aData: Pointer): Boolean;
type
TExecute = function(aParam: Pointer): Boolean of object;
var
Routine: TMethod;
Execute: TExecute;
begin
Result := True;
Routine.Data := Self;
Routine.Code := MethodAddress(UpperCase(aName));
if Routine.Code <> nil then
begin
Execute := TExecute(Routine);
Result := Execute(aData);
end;
end;
5楼: 就是这个东西了,不过还有没有更简单点的效率高点的方法?
再有Routine.Data := Self;这一句,这个CallByName函数要是不在类里写,那么这个Self从哪里取得?
6楼: 写多少个DLL无关紧要,1个也行,100个也行,无所谓。DLL在整个运行期只会调入内存一次,你有多少个客户访问都没事,只要你的网络设施能够承受。
上面的程序基本就是这个思路,
库存管理软件版7楼: 不一样的,执行一次LoadLibrary就会调入内存一次
8楼: to tseug:
举个例子:
type
TGetName = Class
published
function GetMyName: String;
function GetHeName: String;
end;
function TCFeng.GetMyName: String;
begin
Result:= ''Me'';
end;
function TCFeng.GetHeName: String;
begin
Result:= ''UnKnow'';
end;
{--------------------------------------------------}
procedure TForm1.Button3Click(Sender: TObject);
type
TExecute = function: String of object;
var
Routine: TMethod;
Execute: TExecute;
SName: String;
begin
Routine.Data:= TGetName;
SName:= ''GetMyName'';
Routine.Code:= MethodAddress(UpperCase(SName));
if Routine.Code <> nil then
begin
Execute:= TExecute(Routine);
Caption:= Execute;
end;
end;
这样为什么不行?
9楼: 可以了,忘了在MethodAddress前加TGetName.了,
谢谢,接受答案
10楼: 那怎么确定此SName对应哪个TExecute呢?