1 (edited by mathmathou 2015-12-15 01:24:51)

Topic: [Solved] Array and tableGrid

Hello Dmitry and all MVD fans,


I know, I know, I am the champion of hawkward questions... I'm sorry smile


Anyway, here is the problem.


Lets say I have a string like this :


 artist_url := 'Me,URL1,You,URL2,Him,URL3';

As you see, it is coma seperated.


So, logicaly, I split this string into an array :


artist_array := SplitString(artist_url,',');

and so I get an array with 6 lines indexed from 0 to 5 like :


artist_array[0] -> Me
artist_array[1] -> URL1
artist_array[2] -> You
artist_array[3] -> URL2
artist_array[4] -> Him
artist_array[5] -> URL3


great....


Now,  how can I display the result in a TableGrid like this  ? :


http://i.imgur.com/izVX0rF.jpg


Do you see the problem ? I've tried to use odd(i) and even(i) but failed miserably...


1- How would you do ?
2- Is it the best solution for what I'm trying to do (the array) ? Maybe a 2 dimentional array ?


Cheers


Mathias

I'm a very good housekeeper !
Each time I get a divorce, I keep the house

Zaza Gabor

Re: [Solved] Array and tableGrid

TableGrid designed only for display result of SQL query, so you should save this data to database then you can display it.

Dmitry.

Re: [Solved] Array and tableGrid

Thank you Dmitry,


For the record and for others information, I decided to use a temporary database table like this :

string1 :='URL1,Me,URL2,You,URL3,Him,URL4,Them';
    array1 := SplitString(string1,',');
    for i := 0 to length(array1) div 2 - 1 do
        begin
            SQLExecute('INSERT INTO tmp_table(tmp_name,tmp_url) VALUES("'+array1[i*2+1]+'","'+array1[i*2]+'")');
        end;

    Form1.TableGrid2.dbSQL:='SELECT tmp_name,tmp_url FROM tmp_table';
    Form1.TableGrid2.dbGeneralTable := 'tmp_table';
    Form1.TableGrid2.dbListFieldsNames := 'Name,URL';
    Form1.TableGrid2.dbSQLExecute;

    SQLExecute('DELETE FROM tmp_table');

Works fine, but I'll have another question for you. That will be another post smile


Cheers


Mathias

I'm a very good housekeeper !
Each time I get a divorce, I keep the house

Zaza Gabor