Null error

khhkhh
edited 7:46AM in FastReport 2.xx VCL
begin
rtID := [rt];

MyArr[1] := 'A';
MyArr[2] := 'B';
MyArr[3] := 'C';

memo10.lines.clear;
memo10.lines.add(MyArr[rtID]);
end


I get 'Could not convert variant of type [Null] into type [String]'
This when there is no data!


How I can convert a Null into String?

Thank you

Comments

  • gordkgordk St.Catherines On. Canada.
    edited 7:46AM
    Yes I would expect that error you have hard coded a bad index value to occur
    the index values you have given MyArr[] when you added data to the array elements have no relation to either rtid or rt the value you are using as an index when trying to retreive the value stored in the array elements.
    begin
    rtID := [rt];

    MyArr[1] := 'A';
    MyArr[2] := 'B';
    MyArr[3] := 'C';

    memo10.lines.clear;
    memo10.lines.add(MyArr[rtID]);
    end

    In other words the only valid data in MyArr lies in elements with an index value of 1 to 3, any other value in rtid will produce the error because the array element index value is non existent.
    So it is up to the programmer to supply valid index values when loading data into and retrieving data from the array.
    for a good example of how to use the array see the
    fr\demo\reports demo project and look at the report titled group totals in header.
    regards ;)
  • khhkhh
    edited 7:46AM
    I tried this

    if [rt]=nil then
    rtID := 0
    else
    rtID := [rt];

    MyArr[0] := '0';
    MyArr[1] := 'A';
    MyArr[2] := 'B';
    MyArr[3] := 'C';

    memo10.lines.clear;
    memo10.lines.add(MyArr[rtID]);


    I get 'Undefined symbol ''NIL'''

    ?!!!!!!!!!!!!!!!!
  • gordkgordk St.Catherines On. Canada.
    edited 7:46AM
    nil is not usable in the script
    again
    look at the demo as suggested and you will see the correct way to use an array and its index.
    regards ;)

Leave a Comment

Rich Text Editor. To edit a paragraph's style, hit tab to get to the paragraph menu. From there you will be able to pick one style. Nothing defaults to paragraph. An inline formatting menu will show up when you select text. Hit tab to get into that menu. Some elements, such as rich link embeds, images, loading indicators, and error messages may get inserted into the editor. You may navigate to these using the arrow keys inside of the editor and delete them with the delete or backspace key.