#1 2018-03-13 08:00:42

dbacc55
Member
Registered: 2018-03-13
Posts: 3

How fill firemonkey grid from code? upd: Sample inside

Can any show simple example?
I watch 27 - CrossPlatform Clients, but in this sample no grid. Thank you for advice!

Last edited by dbacc55 (2018-03-19 13:59:22)

Offline

#2 2018-03-16 05:08:21

dbacc55
Member
Registered: 2018-03-13
Posts: 3

Re: How fill firemonkey grid from code? upd: Sample inside

any help or advice?

Offline

#3 2018-03-16 08:15:58

ab
Administrator
From: France
Registered: 2010-06-21
Posts: 14,240
Website

Re: How fill firemonkey grid from code? upd: Sample inside

Use a TStringGrid, filling it with the data from code.

Offline

#4 2018-03-19 10:37:14

noobies
Member
Registered: 2011-09-13
Posts: 139

Re: How fill firemonkey grid from code? upd: Sample inside

hi, i try create sample use example https://synopse.info/forum/viewtopic.php?id=1115
and all be ok, but i find new function

    function ToObjectList<T: TSQLRecord>: TObjectList<T>; overload;

and try to use it, but function not works fine, only get all records but not data in fields
i try debug and find forgot RecordType

    function ToObjectList<T: TSQLRecord>(RecordType: TSQLRecordClass=nil): TObjectList<T>; overload;

AB pls add

Type
  TSQLRest = class
...
    function RetrieveList(Table: TSQLRecordClass; const FormatSQLWhere: PUTF8Char;
      const BoundsSQLWhere: array of const;
      const aCustomFieldsCSV: RawUTF8=''): TObjectList<TSQLRecord>; overload;
...
function TSQLRest.RetrieveList(Table: TSQLRecordClass; const FormatSQLWhere: PUTF8Char;
  const BoundsSQLWhere: array of const;
  const aCustomFieldsCSV: RawUTF8=''): TObjectList<TSQLRecord>; 
var SQL: RawUTF8;
    T: TSQLTable;
begin
  result := nil;
  if (self=nil) or (Table=nil) then
    exit;
  T := MultiFieldValues(Table,aCustomFieldsCSV,FormatSQLWhere,BoundsSQLWhere);
  if T<>nil then
  try
    result := T.ToObjectList<TSQLRecord>(Table);
  finally
    T.Free;
  end;
end;

and fix function to ToObjectList<T: TSQLRecord>

    function ToObjectList<T: TSQLRecord>(RecordType: TSQLRecordClass=nil): TObjectList<T>; overload;
...
function TSQLTable.ToObjectList<T>(RecordType: TSQLRecordClass=nil): TObjectList<T>;
var R,Item: TSQLRecord;
    Row: PPUtf8Char;
    i: integer;
begin
  result := TObjectList<T>.Create; // TObjectList<T> will free each T instance
  if (self=nil) or (fRowCount=0) then
    exit;
  R := RecordType.Create;
//  R := TSQLRecordClass(T).Create;
  try
    R.FillPrepare(self);
    Row := @fResults[FieldCount];     // Row^ points to first row of data
    result.Count := fRowCount;
    for i := 0 to fRowCount-1 do begin
//      Item := TSQLRecordClass(T).Create;
      Item := RecordType.Create;
    {$ifdef ISDELPHIXE3}
      PPointerArray(result.List)[i] := Item; // faster than manual Add()
    {$else}
      Result.Add(Item);
    {$endif}
      R.fFill.Fill(pointer(Row),Item);
      Item.fInternalState := Self.InternalState;   // Filling InternalState property
      Inc(Row,FieldCount); // next data row
    end;
  finally
    R.Free;
  end;
end;

all sample project is based on a project (04 - HTTP Client-Server) by add Project04ClientFMX.dpr
https://www.dropbox.com/sh/64f4j4akzp8r … D-Y7a?dl=0

Offline

#5 2018-03-19 10:40:32

noobies
Member
Registered: 2011-09-13
Posts: 139

Re: How fill firemonkey grid from code? upd: Sample inside

i think be a cool if u add Project04ClientFMX.dpr to sample source folder

Last edited by noobies (2018-03-19 10:40:49)

Offline

#6 2018-03-19 13:57:09

dbacc55
Member
Registered: 2018-03-13
Posts: 3

Re: How fill firemonkey grid from code? upd: Sample inside

Thank you noobies for sample

Offline

#7 2018-03-20 07:42:38

mpv
Member
From: Ukraine
Registered: 2012-03-24
Posts: 1,544
Website

Re: How fill firemonkey grid from code? upd: Sample inside

@noobies - it's very hard to maintainers to analyze proposed changes from the forum post. The common way to contribute to open source project is to create a pull request on github. In this case everyone can see the diff between original and modified code. The same is about adding samples. Please, save @ab's time smile

Offline

#8 2018-03-21 12:06:54

noobies
Member
Registered: 2011-09-13
Posts: 139

Re: How fill firemonkey grid from code? upd: Sample inside

Offline

#9 2018-03-21 12:27:36

ab
Administrator
From: France
Registered: 2010-06-21
Posts: 14,240
Website

Re: How fill firemonkey grid from code? upd: Sample inside

Welcome on github, and congrats for the first pull request!
Well done!

I made some comments, but I don't understand why you wanted to use generics here, since they are SOOO broken in Delphi.
The regular TSQLSomeRecord.FillPrepare/FillOne pattern is much preferred, and more efficient.

Offline

#10 2018-03-21 13:09:21

noobies
Member
Registered: 2011-09-13
Posts: 139

Re: How fill firemonkey grid from code? upd: Sample inside

@ab
Because I do not understand how to make an example without using generics in fmx sad

Last edited by noobies (2018-03-21 13:09:36)

Offline

Board footer

Powered by FluxBB