Delphi 如何获得_id";来自kinvey.com的字段值
我一直在使用kinvey.com,每次我试图获取Delphi 如何获得_id";来自kinvey.com的字段值,delphi,backend,delphi-xe6,kinvey,Delphi,Backend,Delphi Xe6,Kinvey,我一直在使用kinvey.com,每次我试图获取漫画。\u id它都返回空值。你能帮我找出原因吗 TManga = class strict private FSite, FManga, FID: String; published property Site : string read FSite write FSite; property Manga : string read FManga
漫画。\u id
它都返回空值。你能帮我找出原因吗
TManga = class
strict private
FSite,
FManga,
FID: String;
published
property Site : string read FSite write FSite;
property Manga : string read FManga write FManga;
property _id : string read FID write FID;
///////////////////////////////////////////////////////////////////////////
var
Mangas: TBackendObjectList<TManga>;
Manga : TManga;
QueryStr: TArray<string>;
i: Integer;
begin
with xQuery do
begin
Execute;
Mangas := TBackendObjectList<TManga>.Create;
QueryStr := TArray<string>.Create('');
xStorage.Storage.QueryObjects<TManga>('xxxx' ,QueryStr ,Mangas);
with xListBox do
begin
Items.BeginUpdate;
try
Items.Clear;
for I := 0 to Mangas.Count -1 do
begin
Manga := Mangas.Items[I];
items.add(Manga.Site + ' - ' + Manga._id) // Manga._id this is everytime null
end;
finally
Items.EndUpdate;
end;
end;
end;
var
漫画:TBackendObjectList;
漫画:特曼加;
QueryStr:柏油树;
i:整数;
开始
使用xquerydo
开始
处决
Mangas:=TBackendObjectList.Create;
QueryStr:=TArray.Create(“”);
xStorage.Storage.QueryObjects('xxxx',QueryStr,Mangas);
用xListBox做什么
开始
Items.BeginUpdate;
尝试
项目。清晰;
对于I:=0到Mangas.Count-1 do
开始
漫画:=Mangas.Items[I];
items.add(Manga.Site+'-'+Manga.\u-id)//Manga.\u-id每次为空
终止
最后
Items.EndUpdate;
终止
终止
终止
您是否尝试在QueryStr的一个数组元素中使用值“fields=\u id”呢?您的列\u id始终为空,因为Kinvey API没有将\u id列作为简单列,而是作为记录的对象id。 要获取漫画记录的对象ID,必须添加如下变量:
oEntity: TBackendEntityValue;
所以在“for”语句的这一行下面:
Manga := Mangas.Items[I];
您可以添加以下两个新行:
oEntity := FBackendList.EntityValues[Manga]; // Gets the Kinvey object
Manga._id := oEntity.ObjectID; // Sets the _id property of the current TManga instance
您可能会记住的一件重要事情是何时在Kinvey收藏中添加新记录。在创建新记录之前,您不必写入新TManga项的_id属性。但是,在插入新记录后,您需要立即从Kinvey处获得它。
此代码改编自Embarcadero的ToDo示例:
procedure TDataModule1.AddBackendItem(const AItem: TManga);
var
oEntity: TBackendEntityValue;
begin
// After the execution of this command the new record will be inserted in Kinvey, and the variable oEntity will get the respective object ID
BackendStorage1.Storage.CreateObject<TManga>(
TMangaNames.BackendClassname, AItem, oEntity);
AItem._id := oEntity.ObjectID; // Updates the property _id of the current instance of TManga
FBackendList.Add(AItem, oEntity);
end;
程序TDataModule1.AddBackendItem(常数:TManga);
变量
oEntity:TBackendEntityValue;
开始
//执行此命令后,新记录将插入Kinvey,变量oEntity将获得相应的对象ID
BackendStorage1.Storage.CreateObject(
TMangaNames.BackendClassname,AItem,oEntity);
AItem.\u id:=oEntity.ObjectID;//更新TManga当前实例的属性_id
FBackendList.Add(AItem,oEntity);
终止
我希望它能帮助你 实际创建对象的代码在哪里?你也可以在漫画中使用
,这样你就不必每次都把mangasi.items[I]
分配给Manga
。其他属性的值是否正确?我感觉xStorage.Storage.QueryObjects('xxxx',QueryStr,Mangas)中存在这个问题;如我所想,当您为“for in子句”填写数据…@TeunPronk thx时。和其他每个属性的真值,但只有Manga。_id每次都返回null。@Zam“xStorage.Storage.QueryObjects('xxxx',QueryStr,Mangas)”请不要在此处指定问题,否则我无法指定find@user3825157如果您正在调试,所有属性都会正确设置吗?你能把你的代码贴在你的物体上吗?你在代码中看不到问题,但其他人可能会:)你可能还需要添加其他字段,以防止它们为空。对不起,但我实际上想将其添加为注释,而不是答案。