You are not logged in.
Pages: 1
Guys
I've implemented a interface based service, and retrieve data with TDocVariant type param.
When display this data, field type missed. I've tried Table.SetFieldType, but colum value disappeared. T_T
Here is the sample code. Enviroment: Win7/X64/XE2
unit uMain;
interface
uses
Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants, System.Classes, Vcl.Graphics,
Vcl.Controls, Vcl.Forms, Vcl.Dialogs, Vcl.Grids, Vcl.StdCtrls;
type
TForm1 = class(TForm)
DrawGrid1: TDrawGrid;
Button1: TButton;
procedure Button1Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
uses
SynCommons,
mORMot,
mORMotUI;
type
TEnumSample = (esOne, esTwo, esThree);
TSQLMyRecord = class(TSQLRecord)
private
fSample: TEnumSample;
published
property Sample: TEnumSample read fSample write fSample;
end;
procedure TForm1.Button1Click(Sender: TObject);
const
MaxCount = 10;
var
oTable, oRow: Variant;
iIdx, iHigh: Integer;
begin
oTable := _Arr([]);
oRow := _Obj([]);
for iIdx := 0 to MaxCount do
begin
iHigh := Ord(esThree) + 1;
oRow.Sample := TEnumSample(iIdx mod iHigh);
oTable._ := oRow;
end;
with TSQLTableToGrid.Create(DrawGrid1,
TSQLTableJSON.Create('', VariantSaveJSON(oTable)), nil) do
begin
Table.SetFieldType('Sample', sftEnumerate, TypeInfo(TEnumSample));
end;
end;
end.
Last edited by uian2000 (2014-08-26 12:11:24)
Offline
In fact, current implementation expected the following expression:
Table.SetFieldType('Sample', sftEnumerate, PTypeInfo(TypeInfo(TEnumSample))^.EnumBaseType);
which was indeed a bit confusing, I understand!
I've modified SetFieldType() to accept the raw TypeInfo() pointer, as you did expect.
See http://synopse.info/fossil/info/d8ba1796c8
It will work for both enumerates and sets.
Thanks for the feedback.
With a little sample project to reproduce the issue, it is just perfect!
Offline
Thanks ab!
It's very kind of you to improve expression so quickly!
Thanks for your work. It's awesome!
Last edited by uian2000 (2014-08-26 16:43:16)
Offline
Pages: 1