I'm trying to make a graph with the integers associated to some cities. To make the adjacency list I need to get the city index of the destinations (Travels) which are in an array of strings (CityNames). When I use StrUtils.IndexStr I get:
Test.pas(34,81) Error: Incompatible type for arg no. 2: Got "Array[0..3] Of ShortString", expected "{Open} Array Of UnicodeString"
The data type ShortString is already used through the program so I need some way of using IndexOf with it.
Also is this the right way to use the TStringList? I'm creating it once for each city.
Here is the compiling code and the error commented:
program Test;
{$MODE OBJFPC}
uses
Classes, SysUtils, StrUtils;
type
TCity = (NY = 0, LONDON = 1, MOSCU = 2, OTHER = 3);
const
TCities: array[0..3] of TCity = (NY, LONDON, MOSCU, OTHER);
CityNames: array[0..3] of string = ('new york','london','moscu','other city');
Travels: array[0..3] of string = ('london,moscu',
'moscu',
'"new york","other city"',
''); // 'other city' doesn''t have travels
procedure ListDestinations;
var
i, j: Integer;
travelsList: TStringList;
begin
for i := 0 to Length(TCities) - 1 do
begin
travelsList := TStringList.Create;
travelsList.Delimiter := ',';
travelsList.DelimitedText := Travels[i];
WriteLn('Destinations from ' + CityNames[ord(TCities[i])] + ': ');
for j := 0 to pred(travelsList.Count) do
begin
WriteLn(travelsList[j] + ' ');
// WriteLn(travelsList[j] + ' ' + IntToStr(IndexStr(travelsList[j], CityNames)));
end;
end;
end;
begin
ListDestinations;
end.