Topic: incompatible Value

In the next code i make a loop to get foreignkey from tablegrid1 but as i added the loop variable in this line(myvalue := MReport.TableGrid1.Cell[1,viii];    )  i get error in viii as incompatible  , what i have to use ?

 var
 viii,myvalue  : integer;

    var  viii: integer; 
begin

     for viii := 0 to Report.tablegrid1.RowCount-1 do
    begin


myvalue := Report.TableGrid1.Cell[1,viii];    

     showmessage(myvalue );

    end;
end;

Re: incompatible Value

viii,myvalue  : integer;
var  viii: integer; 

Re: incompatible Value

You might want to look at this post to understand the loop you are trying to use: https://myvisualdatabase.com/forum/view … hp?id=8920

4 (edited by sparrow 2024-04-17 19:01:52)

Re: incompatible Value

myvalue := Report.TableGrid1.Cell[1,viii].AsInteger;
or
myvalue := StrToInt(Report.TableGrid1.Cells[1,viii]);


http://myvisualdatabase.com/help_en/scr … egrid.html

Re: incompatible Value

Thank you very much. I saw the page, but I got stuck there. Now I get a 'list index out of bounds' error on the same line." why ?



sparrow wrote:
myvalue := Report.TableGrid1.Cell[1,viii].AsInteger;
or
myvalue := StrToInt(Report.TableGrid1.Cells[1,viii]);


http://myvisualdatabase.com/help_en/scr … egrid.html

Re: incompatible Value

Hi,
It's a lot easier if you attach your project - then it's possible to be totally sure what your problem could be.
However, in the case of this error message, it almost certainly refers to the fact that you are referencing a column in a tablegrid that doesn't exist (remember that column and row counts start from 0 and not 1).
Some general points to also consider.
1.  every cell in a tablegrid is handled as 'text' (or 'string').  So if you want to display the contents of individual cells in a message box,  you can do this directly without needing to use a variable or worry about converting to a specified field type (see line 9 in the script).
2.  the contents of any cell can be copied and displayed in an 'edit field' because no conversion is needed (because all cells in a tablegrid are held as text, as explained above);  see line 7 in the script and try changing the column no' to something else and you can see that it still works.
3.  if you need to copy and display, for example, a date/time value from a tablegrid (text) in a 'datetimepicker field', you need to explicitly convert it (see line 8 in the script).  This is also true for other field types.
Hopefully that makes things a bit clearer.
Regards,
Derek.

Post's attachments

Attachment icon display foreign key.zip 445.23 kb, 29 downloads since 2024-04-18