-1
if (FDQuery.FieldDefList.FieldDefs[i].Name <> 'TKey') and (FDQuery.FieldByName(FDQuery.FieldDefList.FieldDefs[i].Name).AsString <> '') then
  begin
    .......
  end

I are migrating code from NexusDB to using MySql.

The table in question has data in it as this line works

a := FDQuery.FieldByName('Employee').AsString; 

The if statement above worked fine using TnxTable.

This portion of the statement works "FDQuery.FieldDefList.FieldDefs[i].Name" as the field names tick over in the loop. however the data in the field does not get read.

What am I doing wrong or how do I do the same thing different.

Thanks

Daniel

sddk
  • 1,115
  • 1
  • 10
  • 20
  • And what does the debugger show you if you set a breakpoint at that line and examine each part of the `if` statement? – Ken White Feb 17 '16 at 13:52
  • The field name is correct. But the data in the field is incorrect. – Daniel Rogers Feb 18 '16 at 01:17
  • I have established that for some reason the data is there during my create form routine but is lost when my TMS grid tile is populated. – Daniel Rogers Feb 18 '16 at 01:18
  • I can't explain why your data is lost, because I can't see how your data gets there, how you're reading it in your *create form routine*, and can't make any sense of what you're trying to do with your (mis)use of `FieldDefList` and the unnecessary noise in your `if` statement. Use a single string variable, assign `FieldDefList.FieldDefs[i].Name` to that string variable by reading it once, and use that variable in the `if` statement. What happens then with that much cleaner (and easier to debug) code? – Ken White Feb 18 '16 at 01:20
  • Copy of code in my Create form routine – Daniel Rogers Feb 18 '16 at 01:57
  • procedure TForm1.FormCreate(Sender: TObject); var i: integer; it: TTMSFMXTile; List: TTMSFMXListView; Note: string; begin with EmpList do begin EmpList.Visible := True; Columns := FDEmployee.RecordCount; Rows := 1; FDEmployee.First; while not FDEmployee.Eof do begin – Daniel Rogers Feb 18 '16 at 02:00
  • it := Tiles.Add; it.StyleLookup := '[custom]defaulttile1'; it.Badge := FDEmployee.FieldByName('Employee').AsString; it.Caption := FDEmployee.FieldByName('SName').AsString + ', ' + FDEmployee.FieldByName('FName').AsString; it.DetailSizePercentage := 30; it.Tag := FDEmployee.FieldByName('TKey').AsInteger; FDEmployee.Next; end; EndUpdate; end; end; – Daniel Rogers Feb 18 '16 at 02:00
  • with FDEmployee do begin First; while ((FIelds.FieldByName('TKey').AsInteger <> ATile.Tag) and (not Eof)) do Next; for I := 0 to FDEmployee.FieldDefList.Count - 1 do begin FieldName := FDEmployee.FieldDefList.FieldDefs[i].Name; if (FieldDefList.FieldDefs[i].Name <> 'TKey') and (Fields.FieldByName(FieldName).AsString <> '') then begin case StringToCaseSelect(FieldDefList.FieldDefs[i].Name, ['Emplyee', – Daniel Rogers Feb 18 '16 at 02:02
  • Last bit of code is code Im having issues with. What I are trying to do is added lines to a list if the field has data in it. And testing field names to add pre determined comments in the fields. ie I dont want a heap of empty lines because there is no data in the fields. – Daniel Rogers Feb 18 '16 at 02:03
  • Don't put code in comments. Please [edit] the question and put the information there, where it can be easily seen and can be formatted properly. – Ken White Feb 18 '16 at 02:20

1 Answers1

-1

Interesting solution. My question is still why cant I use the original query.

I Created a FDQuery inside the tile display routine and looped through with my original code and it works fine.

Then destroyed the Query at the end of the routine.