Hello all,
Here's what I am trying to do: What I want is for my function to return an array of string. I've got a file which is loaded into a RichEdit called QuestionList. Each line contains a string formatted as such:
Q#####D#:<QUESTION>:<CORRECT ANSWER>:<ANSWER>:<ANSWER>:<ANSWER>
Q##### is the Question number
D# is the difficulty number (1,2 or 3 aka Easy, Normal or Hard
: is to seperate the fields from eachother
This code following I've written to assign the array resulting from this function to a global array (declared in the private section of the form for easy access) to get three arrays with the respective question difficulty.
But for some reason it won't allow me to return an array
from my function, is this simply not possible or am I missing something? If it's just not possible I suppose I could use a plain stringlist. I'm using Delphi 7 Enterprise.
The error I'm getting:
Identifier expected but 'ARRAY' found
+ I get on every line within the function in which i work with result 'Incompatible types'
BobbaFet ![[bobafett] [bobafett] [bobafett]](/data/assets/smilies/bobafett.gif)
Everyone has a right to my opinion.
[/b]
Great Delphi Websites faq102-5352
Here's what I am trying to do: What I want is for my function to return an array of string. I've got a file which is loaded into a RichEdit called QuestionList. Each line contains a string formatted as such:
Q#####D#:<QUESTION>:<CORRECT ANSWER>:<ANSWER>:<ANSWER>:<ANSWER>
Q##### is the Question number
D# is the difficulty number (1,2 or 3 aka Easy, Normal or Hard
: is to seperate the fields from eachother
This code following I've written to assign the array resulting from this function to a global array (declared in the private section of the form for easy access) to get three arrays with the respective question difficulty.
Code:
function GetQuestions(Difficulty: integer): array of string;
var i,j: integer; Str: string;
begin
SetLength(Result,0); j := 0;
hard
for i := 0 to (Form1.QuestionList.Lines.Count - 1) do
begin
Str := Form1.QuestionList.Lines[i];
if StrToInt(Str[8]) = Difficulty then
begin
j := Length(Result); Inc(j);
SetLength(Result,j);
Result[j - 1] := Str;
end;
end;
end;
But for some reason it won't allow me to return an array
from my function, is this simply not possible or am I missing something? If it's just not possible I suppose I could use a plain stringlist. I'm using Delphi 7 Enterprise.
The error I'm getting:
Identifier expected but 'ARRAY' found
+ I get on every line within the function in which i work with result 'Incompatible types'
![[bobafett] [bobafett] [bobafett]](/data/assets/smilies/bobafett.gif)
![[bobafett] [bobafett] [bobafett]](/data/assets/smilies/bobafett.gif)
Everyone has a right to my opinion.
[/b]
Great Delphi Websites faq102-5352