RTC Forums
November 01, 2024, 12:53:35 AM *
Welcome, Guest. Please login or register.

Login with username, password and session length
 
   Home   Help Login Register  
Pages: [1]
  Print  
Author Topic: TRtcDataSet.Last and EOF question  (Read 5398 times)
AndreFM
RTC Expired
*
Posts: 22


« on: September 18, 2011, 02:45:07 AM »

Hi Daniel,
It's really great to find a way to use already FireMonkey in iOS and retrieve data from a server. Great job.
I already managed to install and play with it at simulator and my iPhone and work's really well.

I just found one issue at this example. I added a Memo and put just some lines at procedure RtcResult1Return to view the retrieved data. Initially I tried to add a a TRtcMemDataset, but immediately saw that Data.DB (Embarcadero) is not available for iOS.
I don't know if this is the correct way to show the data, but tried:

Code:
if Data.asFunction.FunctionName = 'select' then
begin
  if Result.isType = rtc_DataSet then
  begin
    Result.asDataSet.First;
    while not Result.asDataSet.eof do
    begin
       Memo1.Lines.Add(Result.asDataSet.FieldByName('Common_Name').AsString);
       Result.asDataSet.Next; //Works and show all data
       // Result.asDataSet.Last;  //Endless Loop!!!!
    end;
  end;
end;

See that the line: Result.asDataSet.Last  didn't work as expected. I just added because i had the .NEXT and later changed to .LAST as I showed other information at Memo and didn't want to fill the Memo. I know this example is horrible, but does the .LAST not trigger the dataset EOF?
Thanks
Logged
D.Tkalcec (RTC)
Administrator
*****
Posts: 1881


« Reply #1 on: September 18, 2011, 12:52:47 PM »

The code you have posted works as designed.

When using a TRtcDataSet, the "EOF" property returns TRUE after you move *beyond* the Last row and NOT when you are located at the Last row. The same way, the "BOF" property returns TRUE after you move *before* the First row and NOT when you are located at the First row.

Would "EOF" return TRUE when you are located on the last row (which is what happens when you call "Last"), then "EOF" would also need to return TRUE after using "First" with a dataset which only has one row, so the loop using "First", "while not EOF" and "Next" would never show the last row.

Btw ... Using "FieldByName" requires more memory and is slower than using the "as..." property directly. Also, the "asString" property accesses the field using the "AnsiString" type. If you are working with text fields, you should use the "asText" property instead, which accesses the field using the "String" type (Unicode String in D2009 and later).

For example, the code below would work faster, use less memory and also display Unicode strings correctly:

Code:
if Data.asFunction.FunctionName = 'select' then
begin
  if Result.isType = rtc_DataSet then
  begin
    Result.asDataSet.First;
    while not Result.asDataSet.eof do
    begin
       Memo1.Lines.Add(Result.asDataSet.asText['Common_Name']);
       Result.asDataSet.Next;
    end;
  end;
end;

There are also other ways to enumerate through a TRtcDataSet. For example, if you wanted to show a specific number of rows, you could use a "for" loop with the "RowCount" property. You can also use the "Row" property to check the current position or move to a new position inside a TRtcDataSet. For more information about working with RTC remote functions and using RTC Value objects, please check the "Quick Start" section inside this Forum.

PS. Should you have more question about the RTC SDK and the question hasn't already been answered, please start a new Topic in the "PRO Support" section, using a subject line which summarizes the question/problem.

Best Regards,
Danijel Tkalcec
Logged
AndreFM
RTC Expired
*
Posts: 22


« Reply #2 on: September 18, 2011, 02:23:41 PM »

Thank you for fast response and the tips. It was a long time that I haven't worked with the EOF flags. I will start with "Quick Start" section ;-)
Regards
Andre
Logged
Pages: [1]
  Print  
 
Jump to:  

Powered by MySQL Powered by PHP Powered by SMF 1.1.21 | SMF © 2015, Simple Machines Valid XHTML 1.0! Valid CSS!
Page created in 0.023 seconds with 17 queries.