unit toyobject;
inte***ce
uses
classes;
type
ttoy = class(tpersistent)
private
fname: string;
published
property name: string read fname write fname;
end;
tgender = (gdmale, gdfemale);
tkitte = class(ttoy)
private
fgender: tgender;
published
property gender: tgender read fgender write fgender;
end;
implementation
end.
unit unit1;
inte***ce
uses
sysutils, classes, dsserver, toyobject;
type
tservermethods1 = class(tcomponent)
private
public
function echostring(value: string): string;
function reversestring(value: string): string;
function gettoy: ttoy;
end;
implementation
uses strutils;
function tservermethods1.echostring(value: string): string;
begin
result := value;
end;
function tservermethods1.gettoy: ttoy;
begin
result := tkitte.create;
tkitte(result).name := 'angry kitte';
tkitte(result).gender := gdfemale;
end;
function tservermethods1.reversestring(value: string): string;
begin
result := strutils.reversestring(value);
end;
end.
procedure tform3.button1click(sender: tobject);
varcommand: tdbxcommand;
unmarshal: tjsonunmarshal;
jsonvalue: tjsonvalue;
toy: ttoy;
begin
command := sqlconnection1.dbxconnection.createcommand;
command.commandtype := tdbxcommandtypes.dsservermethod;
command.text := 'tservermethods1.gettoy';
command.prepare;
command.executeupdate;
unmarshal := tdbxclientcommand(command.parameters[0].connectionhandler).getjsonunmarshaler;
tryjsonvalue := command.parameters[0].value.getjsonvalue(true);
memo1.text := jsonvalue.tostring;
toy := ttoy(unmarshal.unmarshal(jsonvalue));
edit1.text := toy.name;
finally
freeandnil(unmarshal)
endend;
雖然執行出錯, 但看 memo1.text 的內容為:
}它是正確的, 為什麼無法例項化型別? 跟蹤了一下發現, rtti 這裡並不認識 tkitte 型別, 雖然引用了 toyobject, 但 tkitte 型別從未被使用到, 這個被 delphi 給優化掉了
....總之是相當無語, datasnap server 思想上是非常不錯,可惜總是忽略了無數細節
懷念一下 webservice 中 invregistry, 準備之後實現乙個這個類似功能的東東
okkk解決一下上面問題, 在 toyobject 中加幾句寫到
procedure registerclass(aclass: tclass);
begin
end;
initialization
registerclass(ttoy);
registerclass(tkitte);
end.
基本上就長得很像 invregistry.registerxsclass, 再執行上面客戶端示例就正確了
為了方便,下面再貼出完整的 toyobject
unit toyobject;
inte***ce
uses
classes;
type
ttoy = class(tpersistent)
private
fname: string;
published
property name: string read fname write fname;
end;
tgender = (gdmale, gdfemale);
tkitte = class(ttoy)
private
fgender: tgender;
published
property gender: tgender read fgender write fgender;
end;
implementation
procedure registerclass(aclass: tclass);
begin
end;
initialization
registerclass(ttoy);
registerclass(tkitte);
end.
linux中 中括號 中的判斷引數
源自 http www.diybl.com course 6 system linux linuxjs 20081117 151774.html b file 若檔案存在且是乙個塊特殊檔案,則為真 c file 若檔案存在且是乙個字元特殊檔案,則為真 d file 若檔案存在且是乙個目錄,則為真 e...
從HIVE中中查詢
從hive資料庫查詢文件 by ymd 拼接sql語句 string sql select from doc file where contains name wildcard 拼接名稱查詢語句 if stringutils.isnoneempty unstructuredbean.getname ...
Spring中classpath中萬用字元號的使用
說明 無萬用字元,必須完全匹配 classpath user base beans.xml 說明 匹配零個或多個字串 只針對名稱,不匹配目錄分隔符等 例如 user a base beans.xml user b base beans.xml 但是不匹配 user base beans.xml cl...